Project

General

Profile

Actions

Bug #10748

closed

Array#flatten(N) calls to_ary on the (N+1)-level objects

Added by ryannevell (Ryan Nevell) almost 10 years ago. Updated almost 10 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
[ruby-core:67637]

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

flatten.rb (383 Bytes) flatten.rb ryannevell (Ryan Nevell), 01/16/2015 07:45 PM

Related issues 1 (0 open1 closed)

Copied from Ruby master - Bug #5761: Array#flatten(N) calls to_ary on the (N+1)-level objectsClosedmame (Yusuke Endoh)12/14/2011Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0