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: 63b893cfd50f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f98f375cd8fc
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on May 9, 2016

  1. Copy the full SHA
    102644d View commit details
  2. Copy the full SHA
    f98f375 View commit details
Showing with 30 additions and 2 deletions.
  1. +4 −2 core/src/main/java/org/jruby/RubyArray.java
  2. +13 −0 spec/ruby/core/array/max_spec.rb
  3. +13 −0 spec/ruby/core/array/min_spec.rb
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -4206,9 +4206,10 @@ public IRubyObject max(ThreadContext context, Block block) {
int i;

if (block.isGiven()) {
Ruby runtime = context.runtime;
for (i = 0; i < realLength; i++) {
v = eltOk(i);
if (result == UNDEF || RubyComparable.cmpint(context, block.yieldSpecific(context, v, result), v, result) > 0) {
if (result == UNDEF || RubyComparable.cmpint(context, block.yieldArray(context, runtime.newArray(v, result), null), v, result) > 0) {
result = v;
}
}
@@ -4241,9 +4242,10 @@ public IRubyObject min(ThreadContext context, Block block) {
int i;

if (block.isGiven()) {
Ruby runtime = context.runtime;
for (i = 0; i < realLength; i++) {
v = eltOk(i);
if (result == UNDEF || RubyComparable.cmpint(context, block.yieldSpecific(context, v, result), v, result) < 0) {
if (result == UNDEF || RubyComparable.cmpint(context, block.yieldArray(context, runtime.newArray(v, result), null), v, result) < 0) {
result = v;
}
}
13 changes: 13 additions & 0 deletions spec/ruby/core/array/max_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe "Array#max" do
describe "given a block with one argument" do
it "yields in turn the last length-1 values from the array" do
ary = []
result = [1,2,3,4,5].max {|x| ary << x; x}

ary.should == [2,3,4,5]
result.should == 5
end
end
end
13 changes: 13 additions & 0 deletions spec/ruby/core/array/min_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe "Array#min" do
describe "given a block with one argument" do
it "yields in turn the last length-1 values from the array" do
ary = []
result = [1,2,3,4,5].min {|x| ary << x; x}

ary.should == [2,3,4,5]
result.should == 1
end
end
end