Class: APL::AST::Function
- Inherits:
-
Object
- Object
- APL::AST::Function
- Defined in:
- lib/apl/ast/function.rb
Instance Attribute Summary collapse
-
#op ⇒ Object
readonly
Returns the value of attribute op.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #compute! ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(op:, x:, y:) ⇒ Function
constructor
A new instance of Function.
Constructor Details
#initialize(op:, x:, y:) ⇒ Function
Returns a new instance of Function.
6 7 8 9 10 |
# File 'lib/apl/ast/function.rb', line 6 def initialize(op:, x:, y:) @op = op @x = x @y = y end |
Instance Attribute Details
#op ⇒ Object (readonly)
Returns the value of attribute op.
4 5 6 |
# File 'lib/apl/ast/function.rb', line 4 def op @op end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
4 5 6 |
# File 'lib/apl/ast/function.rb', line 4 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
4 5 6 |
# File 'lib/apl/ast/function.rb', line 4 def y @y end |
Instance Method Details
#compute! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/apl/ast/function.rb', line 12 def compute! ops = monadic? ? self.class.monadic : self.class.dyadic block = ops[op] || raise(ArgumentError, "I don't know how to do the #{op} operation.") computed_args = args.map do |arg| begin arg.compute! rescue NoMethodError arg end end block.call *computed_args end |
#eql?(other) ⇒ Boolean Also known as: ==
25 26 27 |
# File 'lib/apl/ast/function.rb', line 25 def eql?(other) [:op, :x, :y].all? {|field| self.send(field) == other.send(field) } end |