Skip to content

Commit

Permalink
Define to_a and to_ary
Browse files Browse the repository at this point in the history
Fix #9

These method definitions are needed for
interacting with array-casting operations
like Array#flatten and Array().
  • Loading branch information
soveran committed Apr 17, 2017
1 parent 80aa415 commit 1812ef4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/nest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def to_s
@ns
end

def to_ary
nil
end

def to_a
nil
end

def call(command, *args)
@rc.call(command, to_s, *args)
end
Expand Down
10 changes: 10 additions & 0 deletions test/nest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,13 @@
assert "s1" == n1.get
end
end

# Operations that call to_a and to_ary
scope do
test "interaction with array-casting operations" do
n1 = Nest.new("foo")

assert_equal [n1], [n1].flatten
assert_equal [n1], Array(n1)
end
end

0 comments on commit 1812ef4

Please sign in to comment.