module Konstructor::KonstructorMethod

Private Instance Methods

konstructor(*several_variants) click to toggle source

konstructor -> nil or konstructor(symbol, …) -> nil or konstructor(string, …) -> nil

If used without params, declares next method as constructor.

module SomeClass
  attr_reader :val

  konstructor
  def create(val)
    @val = val
  end
end

If names are given, call can be placed anywhere, only methods with those names will be declared as constructors.

module SomeClass
  attr_reader :val

  def create(val)
    @val = val
  end

  konstructor :create, :recreate

  def recreate(val)
    @val = val * 2
  end
end

then:

SomeClass.new.val
=> nil
SomeClass.create(3).val
=> 3
SomeClass.recreate(3).val
=> 6

Can be used multiple times with various arguments, all calls add up without overwriting each other.

Can raise several errors inheriting from Konstructor::Error:

ReservedNameError
DeclaringInheritedError
IncludingInModuleError

@!visibility public

# File lib/konstructor/main.rb, line 61
def konstructor(*several_variants) # :doc:
  Konstructor.declare(self, several_variants)
  nil
end