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: 998fb3f22809
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 56ce58a3f3a6
Choose a head ref
  • 4 commits
  • 4 files changed
  • 2 contributors

Commits on Mar 9, 2015

  1. Copy the full SHA
    ac3e0e8 View commit details
  2. Copy the full SHA
    adaad05 View commit details
  3. Copy the full SHA
    940bded View commit details

Commits on Mar 10, 2015

  1. Merge pull request #2672 from bjfish/truffle_array_each_index

    [Truffle] Adding Array#each_index #keep_if to array.rb.
    chrisseaton committed Mar 10, 2015
    Copy the full SHA
    56ce58a View commit details
4 changes: 0 additions & 4 deletions spec/truffle/tags/core/array/each_index_tags.txt

This file was deleted.

6 changes: 0 additions & 6 deletions spec/truffle/tags/core/array/keep_if_tags.txt

This file was deleted.

8 changes: 0 additions & 8 deletions spec/truffle/tags/core/array/try_convert_tags.txt

This file was deleted.

26 changes: 26 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/array.rb
Original file line number Diff line number Diff line change
@@ -38,6 +38,10 @@ def self.[](*args)
ary
end

def self.try_convert(obj)
Rubinius::Type.try_convert obj, Array, :to_ary
end

def &(other)
other = Rubinius::Type.coerce_to other, Array, :to_ary

@@ -419,6 +423,20 @@ def cycle(n=nil)
nil
end

def each_index
return to_enum(:each_index) unless block_given?

i = 0
total = @total

while i < total
yield i
i += 1
end

self
end

def flatten(level=-1)
level = Rubinius::Type.coerce_to_collection_index level
return self.dup if level == 0
@@ -444,6 +462,14 @@ def flatten!(level=-1)
nil
end

def keep_if(&block)
return to_enum :keep_if unless block_given?

Rubinius.check_frozen

replace select(&block)
end

def reverse_each
return to_enum(:reverse_each) unless block_given?