Issue #10748 has been reported by Ryan Nevell.

----------------------------------------
Bug #10748: Array#flatten(N) calls to_ary on the (N+1)-level objects
https://bugs.ruby-lang.org/issues/10748

* Author: Ryan Nevell
* Status: Open
* Priority: Normal
* Assignee: Yusuke Endoh
* ruby -v: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
* Backport: 
----------------------------------------
~~~
$ 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--------------------------------
flatten.rb (383 Bytes)


-- 
https://bugs.ruby-lang.org/