[Solved] Ruby: call initialize method before others in class [closed]


initialize is an instance method in this class, so the def initialize is just setting up the constructor for the class. call.. is calling the class’s call method at the time the class definition is parsed. This code is equivalent to

class Lol < Redstone
  def initialize
    super 2013
  end
end

Lol.call "https://stackoverflow.com/" do |headers|
  "headers"
end

(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 call method). If you need to do something, you could do:

class Lol < Redstone
  def self.init
    #do class setup
  end
  init
  def initialize
    super 2013
  end

  call "https://stackoverflow.com/" do |headers|
    "headers"
  end
end

However, depending on the way you are wanting this to work, that may not do what you want.

solved Ruby: call initialize method before others in class [closed]