Class: APL::AST::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/apl/ast/function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#opObject (readonly)

Returns the value of attribute op.



4
5
6
# File 'lib/apl/ast/function.rb', line 4

def op
  @op
end

#xObject (readonly)

Returns the value of attribute x.



4
5
6
# File 'lib/apl/ast/function.rb', line 4

def x
  @x
end

#yObject (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: ==

Returns:

  • (Boolean)


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