Class: Brujula::TypeExtender::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/brujula/type_extender/method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition:) ⇒ Method

Returns a new instance of Method.



6
7
8
# File 'lib/brujula/type_extender/method.rb', line 6

def initialize(definition:)
  @definition = definition
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



4
5
6
# File 'lib/brujula/type_extender/method.rb', line 4

def definition
  @definition
end

Instance Method Details

#apply_inherit_chainObject



20
21
22
23
24
25
26
# File 'lib/brujula/type_extender/method.rb', line 20

def apply_inherit_chain
  definition.is.inject(definition.dup) do |object, trait|
    Brujula::Mergers::ObjectMerger.new(
      superinstance: trait, instance: object
    ).call
  end
end

#callObject



10
11
12
13
14
# File 'lib/brujula/type_extender/method.rb', line 10

def call
  return definition if definition.is.nil?

  extended_object
end

#extended_objectObject



16
17
18
# File 'lib/brujula/type_extender/method.rb', line 16

def extended_object
  @extended_object ||= apply_inherit_chain
end