On Thu, Sep 30, 2010 at 2:53 PM, Alex Stahl <astahl / hi5.com> wrote:

> But is there a way to call the original method instead of just quitting
> out?
>
>
The super keyword does this, I'm not really sure what it is, a macro maybe?
I just think of it as a function I have available in overridden methods,
like block_given?

Be aware that unless you specify its args, it will pass whatever params the
method originally received.


class Parent
  def self.ruby!(arg = nil)
    puts "Parent.ruby!(#{arg.inspect})"
  end
end

class Child1 < Parent
  def self.ruby!(arg)
    super
    puts "Child1.ruby!(#{arg.inspect})"
  end
end

class Child2 < Parent
  def self.ruby!(arg)
    super(12)
    puts "Child2.ruby!(#{arg.inspect})"
  end
end

class Child3 < Parent
  def self.ruby!(arg)
    super()
    puts "Child1.ruby!(#{arg.inspect})"
  end
end


Child1.ruby!( :abc )
puts
Child2.ruby!( 'abc' )
puts
Child3.ruby!( /abc/ )