From: Mischa Fierer Date: 2009-02-26T21:13:24+09:00 Subject: Re: Where is splat implemented? / How does it work? Thanks for all the replies. I've taken a lot of the stuff here, plus all the examples I could find for the splat, and written what I think is probably the most definitive guide at this point. You can run it yourself, as well, which should be useful. Some of the examples are from a post David Black made a year or so ago, others are from Rick and matz. http://github.com/mischa/splat/tree/master I've also written it so that you can try to guess what the return value will be. Please do let me know if anything is wrong with it, also feel free to fork and add your own examples / tests. Best, M Robert Klemme wrote: > 2009/2/26 minilith@gmail.com : >> => # >>> [1] + o >> => [1, :ary] >> >> The #to_splat method seems to be gone. > > Here's another test set > > 09:31:50 OPSC_Gold_bas_dev_R2.0_foundation$ ruby /tmp/o.rb > "1.8.7" > 1 > 2 > 3 > "--------------" > # > nil > nil > "--------------" > 5 > 6 > 7 > "--------------" > 5 > 6 > 7 > "==============" > 1 > 2 > 3 > "--------------" > error > error > 5 > 6 > 7 > "--------------" > 09:31:55 OPSC_Gold_bas_dev_R2.0_foundation$ ruby19 /tmp/o.rb > "1.9.1" > 1 > 2 > 3 > "--------------" > # > nil > nil > "--------------" > # > nil > nil > "--------------" > 5 > 6 > 7 > "==============" > 1 > 2 > 3 > "--------------" > error > error > error > 09:31:57 OPSC_Gold_bas_dev_R2.0_foundation$ cat /tmp/o.rb > > p RUBY_VERSION > > def t(a,b,c) > p a,b,c, '--------------' > end > > o = Object.new > > def o.to_a > [1,2,3] > end > > q = Object.new > > def q.to_ary > [5,6,7] > end > > a, b, c = *o > p a,b,c, '--------------' > > a, b, c = o > p a,b,c, '--------------' > > a, b, c = *q > p a,b,c, '--------------' > > a, b, c = q > p a,b,c, '==============' > > t(*o) rescue puts "error" > t(o) rescue puts "error" > > t(q) rescue puts "error" > t(*q) rescue puts "error" > 09:32:04 OPSC_Gold_bas_dev_R2.0_foundation$ > > Cheers > > robert -- Posted via http://www.ruby-forum.com/.