Project

General

Profile

Actions

Bug #5759

closed

flatten calls to_ary on everything

Added by trans (Thomas Sawyer) about 13 years ago. Updated almost 12 years ago.

Status:
Rejected
Target version:
ruby -v:
ruby 1.9.3dev (2011-09-23 revision 33323) [x86_64-linux]
Backport:
[ruby-core:41634]

Description

I often ensure that I have an array by doing:

def foo=(x)
@foo = [x].flatten
end

But this has turned into a problem as of late, as it seems #flatten is calling #to_ary on every element in the array, and apparently catching the error raised if #to_ary isn't defined for that object. But that causes potential issues with objects that use #method_missing. I think #flatten should use respond_to?(:to_ary) to make sure an object can handle it before actually calling it.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #6039: lambda vs proc; #to_ary w/ splat bugRejectedmatz (Yukihiro Matsumoto)02/17/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0