instance method
Array#rotate!
(?::int count) -> self
rotate!(count = 1) → self
array.c
View on GitHub ↗
static VALUE
rb_ary_rotate_bang(int argc, VALUE *argv, VALUE ary)
{
long n = (rb_check_arity(argc, 0, 1) ? NUM2LONG(argv[0]) : 1);
rb_ary_rotate(ary, n);
return ary;
}
Rotates self in place by moving elements from one end to the other; returns self.
With non-negative numeric count, rotates count elements from the beginning to the end:
Example
[0, 1, 2, 3].rotate!(2) # => [2, 3, 0, 1] [0, 1, 2, 3].rotate!(2.1) # => [2, 3, 0, 1]
If count is large, uses count % array.size as the count:
Example
[0, 1, 2, 3].rotate!(21) # => [1, 2, 3, 0]
If count is zero, rotates no elements:
Example
[0, 1, 2, 3].rotate!(0) # => [0, 1, 2, 3]
With a negative numeric count, rotates in the opposite direction, from end to beginning:
Example
[0, 1, 2, 3].rotate!(-1) # => [3, 0, 1, 2]
If count is small (far from zero), uses count % array.size as the count:
Example
[0, 1, 2, 3].rotate!(-21) # => [3, 0, 1, 2]
Related: see Methods for Assigning.