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

Commits on Mar 9, 2015

  1. Copy the full SHA
    fb4a9d6 View commit details
  2. Merge pull request #2670 from bjfish/truffle_array_cycle

    [Truffle] Adding Array#cycle to array.rb.
    chrisseaton committed Mar 9, 2015
    Copy the full SHA
    eb53395 View commit details
Showing with 18 additions and 9 deletions.
  1. +0 −9 spec/truffle/tags/core/array/cycle_tags.txt
  2. +18 −0 truffle/src/main/ruby/core/rubinius/common/array.rb
9 changes: 0 additions & 9 deletions spec/truffle/tags/core/array/cycle_tags.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
fails:Array#cycle iterates indefinitely when not passed a count
fails:Array#cycle iterates indefinitely when passed nil
fails:Array#cycle does not rescue StopIteration when not passed a count
fails:Array#cycle does not rescue StopIteration when passed a count
fails:Array#cycle iterates the array Integer(count) times when passed a Float count
fails:Array#cycle calls #to_int to convert count to an Integer
fails:Array#cycle raises a TypeError if #to_int does not return an Integer
fails:Array#cycle raises a TypeError if passed a String
fails:Array#cycle raises a TypeError if passed an Object
fails:Array#cycle raises a TypeError if passed true
fails:Array#cycle raises a TypeError if passed false
18 changes: 18 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/array.rb
Original file line number Diff line number Diff line change
@@ -391,6 +391,24 @@ def bsearch
nil
end

def cycle(n=nil)
return to_enum(:cycle, n) unless block_given?
return nil if empty?

# Don't use nil? because, historically, lame code has overridden that method
if n.equal? nil
while true
each { |x| yield x }
end
else
n = Rubinius::Type.coerce_to_collection_index n
n.times do
each { |x| yield x }
end
end
nil
end

def flatten(level=-1)
level = Rubinius::Type.coerce_to_collection_index level
return self.dup if level == 0