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 #1

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
Actions #2

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]
Actions #3

Updated by wanabe (_ wanabe) almost 10 years ago

  • Backport set to 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0