From: dblack@... Date: 2006-07-16T05:18:09+09:00 Subject: Re: Devious or what? : hacking super : should this work? Hi -- On Sun, 16 Jul 2006, Jeremy Henty wrote: > I've discovered that an unadorned call to "super" need *not* call the > parent method with the same arguments!!! If you bind the entire > argument list to a variable you can modify the list before calling > "super". Check it out: > > class Show > def initialize(*args) > puts args.inspect > end > end > > Show.new(1,34,"asd") > > class Show2 < Show > def initialize(*args) > puts args.shift > super > end > end > > Show2.new(1,34,"asd") > > ===> > > [1, 34, "asd"] > 1 > [34, "asd"] > > So "args" is bound to the *actual* array of arguments, not just a > copy. Is this a bug or a feature? Might this behaviour change in > future? I assume it's a feature. 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. David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy http://www.manning.com/black => RUBY FOR RAILS (reviewed on Slashdot, 7/12/2006!) http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log dblack@wobblini.net => me