The presence of several designers in ruby

Is there a way to have multiple “initializing” methods in ruby? For example: one method excluding one argument, while the other excludes three?

Sort of

 class One
  def initialize (a)
    puts a
  end
  def initialize_1 (a,b)
    puts a ,b 
  end
end
+5
source share
1 answer

initializenot really a constructor. You really can have two constructors.

class One
  singletonclass.class_eval{alias old_new :new}
  def self.new a
    puts a
    old_new
  end
  def self.new_1 a, b
    puts a, b
    old_new
  end
end
+5

All Articles