Hi there,
whilst looking at the Rails source code, I noticed a number of methods that followed this pattern:
def initialize #some initialisation code super end
I thought that the appropriate way to do this was to call super before the init stuff, just in case the parent init code overrode the current init code.
Consider the following:
>> class First >> def cheese >> puts @cheese >> end >> def initialize >> @cheese = 'Stilton' >> end => nil >> First.new.cheese Stilton => nil >> class Second < First >> def initialize >> @cheese = 'Shropshire Blue' >> super >> end => nil >> Second.new.cheese Stilton => nil >> class Third < First >> def initialize >> super >> @cheese = 'Cheshire' >> end => nil >> Third.new.cheese Cheshire
However, the occasional call to super at the end of a method may be because you desire this behaviour, I'm just being inquisitive
An example where I imagine the super would be better placed at the beginning of the method:
(actionpack/lib/action_controller/cgi_process.rb) def initialize(cgi, session_options = {}) @cgi = cgi @session_options = session_options @env = @cgi.send(:env_table) super() end
Cheers, Sam Aaron