Method: Immutable::Vector#rotate
- Defined in:
- lib/immutable/_core.rb
#rotate(count = 1) ⇒ Vector
Return a new Vector with the same elements, but rotated so that the one at
index count is the first element of the new vector. If count is positive,
the elements will be shifted left, and those shifted past the lowest position
will be moved to the end. If count is negative, the elements will be shifted
right, and those shifted past the last position will be moved to the beginning.
1526 1527 1528 1529 |
# File 'lib/immutable/_core.rb', line 1526 def rotate(count = 1) return self if (count % @size) == 0 self.class.new(((array = to_a).frozen? ? array.rotate(count) : array.rotate!(count)).freeze) end |