-
Notifications
You must be signed in to change notification settings - Fork 1
Limitations
Dima Lashkov edited this page Jan 23, 2017
·
14 revisions
Using reserved method names new
and initialize
for additional
constructor declaration will raise an error:
konstructor
def initialize # raises Konstructor::ReservedNameError
end
or
konstructor
def new # raises Konstructor::ReservedNameError
end
Modules can't have konstructors. Use ActiveSupport::Concern
and
declare konstructor in included
block.
module SomeModule
extend ActiveSupport::Concern
included do
konstructor :create
end
# konstructor <- would raise Konstructor::IncludeInModuleError
def create
end
end
Methods inherited from superclasses can't become konstructors in subclasses. To achieve the effect, define a new method, mark it as konstructor and call the inherited one.
class SomeClass
def create(val)
@val = val
end
attr_reader :val
end
class SomeSubclass < SomeClass
# konstructor :create <- would raise Konstructor::DeclaringInheritedError
konstructor
def complex_create(val1, val2)
super(val1 + val2)
end
end
obj = SomeSubclass.complex_create(2, 3)
obj.val # 5