Class: Operation
- Inherits:
-
Object
- Object
- Operation
- Defined in:
- lib/subsystem.rb
Overview
The Operation class is the Hitsuji representation of an equation, and its properties include a name, a value and a block. The value is an Linker with read-write properties, and the values in this Linker are parsed into the block for execution. This block is only executed upon read of dependent values. Once the Operation is bound, a seperate method must be used to read them. Linkers are the main interface between Items and Operations. Examples of its use can be seen in the documentation for the Hitsuji.operation method.
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#input ⇒ Object
Returns the value of attribute input.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(name, input, block) ⇒ Operation
constructor
A new instance of Operation.
Constructor Details
#initialize(name, input, block) ⇒ Operation
Returns a new instance of Operation.
39 40 41 42 43 44 |
# File 'lib/subsystem.rb', line 39 def initialize(name, input, block) @name = name @input = input src = MethodSource.source_helper(block.source_location) @block = 'proc ' + src.match(/(do|\{)+?(.|\s)*(end|\})+?/).to_s end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
61 62 63 |
# File 'lib/subsystem.rb', line 61 def block @block end |
#input ⇒ Object
Returns the value of attribute input.
62 63 64 |
# File 'lib/subsystem.rb', line 62 def input @input end |
#name ⇒ Object
Returns the value of attribute name.
62 63 64 |
# File 'lib/subsystem.rb', line 62 def name @name end |
Instance Method Details
#call ⇒ Object
46 47 48 |
# File 'lib/subsystem.rb', line 46 def call eval(@block).call(recurse(@input.value)) end |