Skip to content

Commit

Permalink
Literal::Array#rotate
Browse files Browse the repository at this point in the history
Closes #196
  • Loading branch information
joeldrapper committed Dec 2, 2024
1 parent a413ffb commit 11f94d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/literal/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ def replace(value)
self
end

def rotate(...)
__with__(@__value__.rotate(...))
end

def rotate!(...)
@__value__.rotate!(...)
self
Expand Down
8 changes: 8 additions & 0 deletions test/array.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,11 @@
expect(result.to_a) == [2, 3, 1]
end

test "#rotate rotates the array" do
array = Literal::Array(Integer).new(1, 2, 3)

result = array.rotate
assert Literal::Array(Integer) === result
expect(result.to_a) == [2, 3, 1]
expect(array.to_a) == [1, 2, 3]
end

0 comments on commit 11f94d1

Please sign in to comment.