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
Updated by ryannevell (Ryan Nevell) almost 10 years ago
- Copied from Bug #5761: Array#flatten(N) calls to_ary on the (N+1)-level objects added
Updated by nobu (Nobuyoshi Nakada) almost 10 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
Applied in changeset r49400.
array.c: reduce to_ary call
- array.c (flatten): no need to call to_ary method on elements
beyond the given level. [ruby-core:67637] [Bug #10748]
Updated by wanabe (_ wanabe) almost 10 years ago
- Backport set to 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
Actions
Like0
Like0Like0Like0