Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 171127899875^
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 25a3876adbe7
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Dec 14, 2015

  1. Fix Enumerable#min_by with nil

    kachick authored and kares committed Dec 14, 2015
    Copy the full SHA
    1711278 View commit details
  2. Fix Enumerable#max_by with nil

    kachick authored and kares committed Dec 14, 2015
    Copy the full SHA
    25a3876 View commit details
Showing with 2 additions and 2 deletions.
  1. +2 −0 core/src/main/java/org/jruby/RubyEnumerable.java
  2. +0 −1 spec/tags/ruby/core/enumerable/max_by_tags.txt
  3. +0 −1 spec/tags/ruby/core/enumerable/min_by_tags.txt
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
@@ -1201,6 +1201,7 @@ 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);
// 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();
@@ -1213,6 +1214,7 @@ public static IRubyObject min_by(ThreadContext context, IRubyObject self, final

@JRubyMethod
public static IRubyObject min_by(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
if (arg == context.nil) return singleExtentBy(context, self, "min", SORT_MIN, block);
// 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 sorted.first(arg);
1 change: 0 additions & 1 deletion spec/tags/ruby/core/enumerable/max_by_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Enumerable#max_by when called with an argument n without a block returns an enumerator
fails:Enumerable#max_by when called with an argument n when n is nil returns the maximum element
1 change: 0 additions & 1 deletion spec/tags/ruby/core/enumerable/min_by_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Enumerable#min_by when called with an argument n without a block returns an enumerator
fails:Enumerable#min_by when called with an argument n when n is nil returns the minimum element