Skip to content

Limitations

Dima Lashkov edited this page Jan 24, 2017 · 14 revisions

When limitation is hit, konstructor raises an exception subclassing Konstructor::Error.

Reserved names

Using reserved method names :new and :initialize in konstructor declaration will raise an error:

  konstructor
  def initialize # raises Konstructor::ReservedNameError
  end

or

  konstructor
  def new # raises Konstructor::ReservedNameError
  end

Declaring inherited methods

Methods inherited from superclasses can't be declared with konstructor in subclasses. To achieve the effect, define a new method, use konstructor on it, 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

Declaring in modules

Modules can't have konstructor declarations. Use ActiveSupport::Concern and put konstructor in included block.

module SomeModule
  extend ActiveSupport::Concern
    
  included do      
    konstructor :create
  end
  
  # konstructor <- would raise Konstructor::IncludingInModuleError
  def create
  end
end        
Clone this wiki locally