Project

General

Profile

Actions

Bug #5761

closed

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

Added by jonleighton (Jon Leighton) over 12 years ago. Updated almost 12 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
Backport:
[ruby-core:41645]

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)
method_missing(to_ary)
respond_to?(to_ary)
[#Foo:0x00000001ae41c8]

[[[Foo.new]]].flatten(2)
method_missing(to_ary)
respond_to?(to_ary)
[#Foo:0x00000001ae3d90]

[[[Foo.new]]].flatten(1)
#<a href="Foo:0x00000001ae3980" class="external">Foo:0x00000001ae3980</a>

$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]

Expected behaviour: no method calls are made on the (N+1)-level objects.

For what it's worth, this is the 1.8.7 output:

$ ruby flatten.rb
[[Foo.new]].flatten(1)
respond_to?(to_ary)
[#Foo:0x7fef3ebb1888]

[[[Foo.new]]].flatten(2)
respond_to?(to_ary)
[#Foo:0x7fef3ebb16a8]

[[[Foo.new]]].flatten(1)
#<a href="Foo:0x7fef3ebb14f0" class="external">Foo:0x7fef3ebb14f0</a>


Related issues 1 (0 open1 closed)

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

Updated by ko1 (Koichi Sasada) about 12 years ago

  • Category set to core
  • Assignee set to mame (Yusuke Endoh)
Actions #2

Updated by shyouhei (Shyouhei Urabe) about 12 years ago

  • Status changed from Open to Assigned

Updated by mame (Yusuke Endoh) almost 12 years ago

  • Status changed from Assigned to Closed

This is already fixed in ruby-1.9.3-p194.

--
Yusuke Endoh

Actions #4

Updated by ryannevell (Ryan Nevell) over 9 years ago

  • Copied to Bug #10748: Array#flatten(N) calls to_ary on the (N+1)-level objects added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0