Actions
Bug #10748
closedArray#flatten(N) calls to_ary on the (N+1)-level objects
Description
$ cat flatten.rb
class Foo
def respond_to?(name, include_private = true)
puts "respond_to?(#{name})"
super
end
def method_missing(name, *args)
puts "method_missing(#{name})"
super
end
end
puts "[[Foo.new]].flatten(1)"
p [[Foo.new]].flatten(1)
puts
puts "[[[Foo.new]]].flatten(2)"
p [[[Foo.new]]].flatten(2)
puts
puts "[[[Foo.new]]].flatten(1)"
p [[[Foo.new]]].flatten(1)
$ ruby flatten.rb
[[Foo.new]].flatten(1)
respond_to?(to_ary)
[#<Foo:0x007fb959177f90>]
[[[Foo.new]]].flatten(2)
respond_to?(to_ary)
[#<Foo:0x007fb959177d10>]
[[[Foo.new]]].flatten(1)
[[#<Foo:0x007fb959177ab8>]]
$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
Expected behaviour: no method calls are made on the (N+1)-level objects.
This is the same as bug #5761, but has resurfaced in a later version.
Files
Actions
Like0
Like0Like0Like0