Sha256: 07ee98e6d45cf6e26a3ea6dc6731d0b5626e4bccb7fdd9237ad77bd7c2085f02
Contents?: true
Size: 376 Bytes
Versions: 4
Compression:
Stored size: 376 Bytes
Contents
class Array # rotate right with size. # if the size is negative, rotate left. # [1,2,3].rotate # => [3,1,2] # # [1,2,3].rotate -1 # => [2,3,1] # # [1,2,3].rotate 2 # => [2,3,1] def rotate n = 1 return self if empty? or n == 0 self[-n..-1] + self[0...-n] end # inplace version of rotate def rotate! replace rotate end end
Version data entries
4 entries across 4 versions & 2 rubygems
Version | Path |
---|---|
godfat-ludy-0.1.13 | lib/ludy/array/rotate.rb |
ludy-0.1.10 | lib/ludy/array/rotate.rb |
ludy-0.1.11 | lib/ludy/array/rotate.rb |
ludy-0.1.13 | lib/ludy/array/rotate.rb |