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

Commits on Mar 10, 2015

  1. Copy the full SHA
    7bab696 View commit details
  2. Merge pull request #2674 from bjfish/truffle_array_rotate

    [Truffle] Adding Array#rotate to array.rb
    chrisseaton committed Mar 10, 2015
    Copy the full SHA
    5223bf2 View commit details
Showing with 20 additions and 14 deletions.
  1. +0 −14 spec/truffle/tags/core/array/rotate_tags.txt
  2. +20 −0 truffle/src/main/ruby/core/rubinius/common/array.rb
14 changes: 0 additions & 14 deletions spec/truffle/tags/core/array/rotate_tags.txt

This file was deleted.

20 changes: 20 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/array.rb
Original file line number Diff line number Diff line change
@@ -485,6 +485,26 @@ def reverse_each
self
end

def rotate(n=1)
n = Rubinius::Type.coerce_to_collection_index n
return Array.new(self) if length == 1
return [] if empty?

ary = Array.new(self)
idx = n % ary.size

ary[idx..-1].concat ary[0...idx]
end

def rotate!(cnt=1)
Rubinius.check_frozen

return self if length == 0 || length == 1

ary = rotate(cnt)
replace ary
end

def find_index(obj=undefined)
super
end