From: Mischa Fierer Date: 2009-02-25T23:52:14+09:00 Subject: Re: Where is splat implemented? / How does it work? David, Thank you for your reply. However, what I'm wondering is, where does it "tie" itself to to_ary/to_a? Also, I think it is not the same thing as to_a, when used like so: >> [[1,2,3].to_a] => [[1, 2, 3]] # outer length = 1 vs >> [*[1,2,3]] => [1, 2, 3] # length = 3 >> Or >> str = "asdf" >> def str.to_a >> ["oops"] >> end => nil >> [*str] => ["oops"] vs >> [str.to_a] => [["oops"]] I'm really curious where / how this happens. If anyone can point me to either rubinius or to mri, I would be very grateful. M David A. Black wrote: > Hi -- > > Mischa Fierer wrote: >> >> Short of reading eval.c, does anyone have any pointers? > > It ties itself to to_a: > > >> obj = Object.new > => # > >> def obj.to_a; [1,2,3]; end > => nil > >> a = *obj > => [1, 2, 3] > > That code works the same in 1.8 and 1.9.1. There may be some classes > where it's optimized away so that you can't override it even by defining > to_a. I'm not sure. > > > David > > -- > David A. Black / Ruby Power and Light, LLC > Ruby/Rails consulting & training: http://www.rubypal.com > Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) > > Ruby Training Atlanta! April 1-3, http://www.entp.com/training/atlanta09 -- Posted via http://www.ruby-forum.com/.