When redefining a class method I want to be able to call super, just as I would in a instance method.
For example, I have a class hi with a class method
Hi.hi
class Hi
def self.hi
puts "hi"
end
end
Hi.hi #=> "hi"
self.hi
class Hi
def self.hi
super
puts "Oh!"
end
end
Hi.hi #=> NoMethodError: super: no superclass method `hi' for Hi:Class
class Hi
class << self
def new_hi
old_hi
puts "Oh!"
end
alias :old_hi :hi
alias :hi :new_hi
end
end
Hi.hi #=> "hi\n Oh!"
Super works for child classes inherited from a parent class.
In your case alias is the only way. Or you can use alias_method:
alias_method :old_hi, :hi
def self.hi
old_hi
puts "Oh!"
end