I have a file with the following code
and i want the initialize method to run first and then call
class Lol < Redstone
def initialize
super 2013
end
call "/" do |headers|
"headers"
end
end
But when i execute this, the method call is first called.
how to fix this?
initializeis an instance method in this class, so thedef initializeis just setting up the constructor for the class.call..is calling the class’scallmethod at the time the class definition is parsed. This code is equivalent to(assuming call is a public class method)
Ruby doesn’t really have the idea of a class constructor, other than the code in the actual class definition (like the
callmethod). If you need to do something, you could do:However, depending on the way you are wanting this to work, that may not do what you want.