Skip to content

Commit 2b1a10a

Browse files
committed
Fix destructure in block parameters with a BasicObject which respond_to?(:to_ary) = true
* Let the SplatCastNode do the correct check and coercion for #to_ary.
1 parent 1858a8e commit 2b1a10a

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

language/block_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,22 @@ def m(a) yield a end
192192
m(obj) { |a, b, c| [a, b, c] }.should == [1, 2, nil]
193193
end
194194

195+
it "calls #respond_to? on a BasicObject to check if object has method #to_ary" do
196+
ScratchPad.record []
197+
obj = BasicObject.new
198+
def obj.respond_to?(name, *)
199+
ScratchPad << [:respond_to?, name]
200+
name == :to_ary ? true : super
201+
end
202+
def obj.to_ary
203+
ScratchPad << :to_ary
204+
[1, 2]
205+
end
206+
207+
m(obj) { |a, b, c| [a, b, c] }.should == [1, 2, nil]
208+
ScratchPad.recorded.should == [[:respond_to?, :to_ary], :to_ary]
209+
end
210+
195211
it "receives the object if it does not respond to #respond_to?" do
196212
obj = BasicObject.new
197213

0 commit comments

Comments
 (0)