Class: Operator
- Inherits:
-
Object
- Object
- Operator
- Defined in:
- lib/mdarray/operators.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arity ⇒ Object
readonly
number of arguments to the operator.
-
#exec_type ⇒ Object
readonly
type of operator execution, e.g., default, in_place, numeric.
-
#fmap ⇒ Object
readonly
function map for this operator.
-
#force_type ⇒ Object
readonly
force this type as the result type.
-
#helper ⇒ Object
readonly
helper method for this operator.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#other_args ⇒ Object
readonly
list of arguments to the operator other than the operands.
-
#post_condition ⇒ Object
readonly
proc to be executed after the operator’s execution.
-
#pre_condition ⇒ Object
readonly
proc to be executed before the operator’s execution.
-
#type ⇒ Object
readonly
resulting type of the operation.
Instance Method Summary collapse
-
#exec(*args) ⇒ Object
—————————————————————————————.
-
#initialize(name, arity, exec_type, force_type = nil, pre_condition = nil, post_condition = nil) ⇒ Operator
constructor
—————————————————————————————.
Constructor Details
#initialize(name, arity, exec_type, force_type = nil, pre_condition = nil, post_condition = nil) ⇒ Operator
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/mdarray/operators.rb', line 98 def initialize(name, arity, exec_type, force_type = nil, pre_condition = nil, post_condition = nil) @name = name @arity = arity @exec_type = exec_type @helper = nil @force_type = force_type @pre_condition = pre_condition # proc to be executed before the main loop @pre_condition_result = nil @post_condition = post_condition # proc to be executed after the main loop end |
Instance Attribute Details
#arity ⇒ Object (readonly)
number of arguments to the operator
85 86 87 |
# File 'lib/mdarray/operators.rb', line 85 def arity @arity end |
#exec_type ⇒ Object (readonly)
type of operator execution, e.g., default, in_place, numeric
86 87 88 |
# File 'lib/mdarray/operators.rb', line 86 def exec_type @exec_type end |
#fmap ⇒ Object (readonly)
function map for this operator
88 89 90 |
# File 'lib/mdarray/operators.rb', line 88 def fmap @fmap end |
#force_type ⇒ Object (readonly)
force this type as the result type
89 90 91 |
# File 'lib/mdarray/operators.rb', line 89 def force_type @force_type end |
#helper ⇒ Object (readonly)
helper method for this operator
87 88 89 |
# File 'lib/mdarray/operators.rb', line 87 def helper @helper end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
83 84 85 |
# File 'lib/mdarray/operators.rb', line 83 def name @name end |
#other_args ⇒ Object (readonly)
list of arguments to the operator other than the operands
92 93 94 |
# File 'lib/mdarray/operators.rb', line 92 def other_args @other_args end |
#post_condition ⇒ Object (readonly)
proc to be executed after the operator’s execution
91 92 93 |
# File 'lib/mdarray/operators.rb', line 91 def post_condition @post_condition end |
#pre_condition ⇒ Object (readonly)
proc to be executed before the operator’s execution
90 91 92 |
# File 'lib/mdarray/operators.rb', line 90 def pre_condition @pre_condition end |
#type ⇒ Object (readonly)
resulting type of the operation
84 85 86 |
# File 'lib/mdarray/operators.rb', line 84 def type @type end |
Instance Method Details
#exec(*args) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/mdarray/operators.rb', line 116 def exec(*args) @pre_condition_result = @pre_condition.call(*args) if @pre_condition result = method(@exec_type).call(*args) (@post_condition)? @post_condition.call(result, *args) : result end |