Skip to content

Commit

Permalink
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
@@ -1272,6 +1272,9 @@ public static IRubyObject max_by(ThreadContext context, IRubyObject self, final
@JRubyMethod
public static IRubyObject max_by(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
if (arg == context.nil) return singleExtentBy(context, self, "max", SORT_MAX, block);

if (!block.isGiven()) return enumeratorizeWithSize(context, self, "max_by", enumSizeFn(context, self));

// TODO: Replace with an implementation (quickselect, etc) which requires O(k) memory rather than O(n) memory
RubyArray sorted = (RubyArray)sort_by(context, self, block);
return ((RubyArray) sorted.last(arg)).reverse();
1 change: 0 additions & 1 deletion spec/tags/ruby/core/enumerable/max_by_tags.txt

This file was deleted.

0 comments on commit b97a0d0

Please sign in to comment.