From: Adam Prescott Date: 2011-08-05T19:06:47+09:00 Subject: [ruby-core:38814] Re: to_ary not respecting respond_to? --90e6ba2121d7ab6a7404a9bf23c7 Content-Type: text/plain; charset=UTF-8 On Thu, Aug 4, 2011 at 11:37 PM, Ryan Davis wrote: > > Extra Info: > http://tenderlovemaking.com/2011/06/28/til-its-ok-to-return-nil-from-to_ary/ > Someone made a comment on that post linking to http://yehudakatz.com/2010/01/02/the-craziest-fing-bug-ive-ever-seen/ which explains, specifically for Array#flatten: ---- In Ruby 1.8, the process is essentially the following: if obj.respond_to?(:to_ary) obj.__send__(:to_ary) else obj end In Ruby 1.9, it was changed to: begin obj.__send__(:to_ary) rescue NoMethodError obj end ---- I'm not sure why that changed happened, but at least that seems to be the source of the behaviour. --90e6ba2121d7ab6a7404a9bf23c7 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Someone made a comment on that post linking to= =C2=A0http://yehudakatz.com/2010/01/02/the-crazies= t-fing-bug-ive-ever-seen/=C2=A0which explains, specifically for Array#f= latten:

----

In Ruby 1.8, the process is es= sentially the following:

if obj.respond_to?(:to_ary)
=C2=A0 = obj.__send__(:to_ary)
else
=C2=A0 obj
end

In Ruby 1.9, it w= as changed to:

begin
=C2=A0 obj.__send__(:to_ary)
rescue NoMethodError
=C2=A0 obj
end

----

I'm not sure why that changed hap= pened, but at least that seems to be the source of the behaviour.
--90e6ba2121d7ab6a7404a9bf23c7--