From: Dominik Bathon Date: 2006-07-16T09:14:15+09:00 Subject: Re: Devious or what? : hacking super : should this work? On Sat, 15 Jul 2006 23:15:05 +0200, Jeremy Henty wrote: > On 2006-07-15, dblack@wobblini.net wrote: >> On Sun, 16 Jul 2006, Jeremy Henty wrote: >> >>> If you bind the entire argument list to a variable you can modify >>> the list before calling "super". Check it out: >> >> ... super should be pretty transparent; for example, if an argument >> is for some reason going to be altered in place by the original >> method, you want that to still happen when you call the method that >> calls super. > > True, but that's not what surprised me. Given "def foo(*args) ..." I > always expected the *members* of args to be the arguments of the > method call (and not copies of them). I did not expect args *itself* > to be part of the Ruby call stack. I assumed it was just a temporary > object created on the fly to give me access to the method arguments. This definitely is the case for Ruby 1.8 and I can't reproduce your example with 1.8.4, only with 1.9. I am not sure why this was changed. In 1.8 the arguments are stored in a C array in the FRAME struct and when splatting is used a new Ruby array is created every time: $ cat super_splat.rb class A def foo(*a); p a, a.object_id; end end class B < A def foo(*a); p a, a.object_id; a.shift; super; end end B.new.foo(1,2,3) $ ruby super_splat.rb [1, 2, 3] -604430366 [1, 2, 3] -604430956 And even in 1.9 it actually is a different Ruby array: $ ruby19 super_splat.rb [1, 2, 3] -604528228 [2, 3] -604528338 Dominik