Class: Gobstones::Lang::TwoArgExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/gobstones/lang/expressions/two_arg_expression.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#evaluate, #is_function_call?

Methods included from EqualityDefinition

#==

Constructor Details

#initialize(left, right) ⇒ TwoArgExpression

Returns a new instance of TwoArgExpression.



21
22
23
24
# File 'lib/gobstones/lang/expressions/two_arg_expression.rb', line 21

def initialize(left, right)
  @left_expr = left
  @right_expr = right
end

Instance Attribute Details

#left_exprObject (readonly)

Returns the value of attribute left_expr.



6
7
8
# File 'lib/gobstones/lang/expressions/two_arg_expression.rb', line 6

def left_expr
  @left_expr
end

#right_exprObject (readonly)

Returns the value of attribute right_expr.



6
7
8
# File 'lib/gobstones/lang/expressions/two_arg_expression.rb', line 6

def right_expr
  @right_expr
end

Class Method Details

.evaluates_with(selector) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gobstones/lang/expressions/two_arg_expression.rb', line 8

def self.evaluates_with(selector)
  instance_eval do
    define_method :evaluate do |*args|
      context = args.first
      left_expr.evaluate(context).send(selector, right_expr.evaluate(context))
    end

    define_method :to_s do
      "#{selector} expression"
    end
  end
end

Instance Method Details

#equality_attributesObject



26
27
28
# File 'lib/gobstones/lang/expressions/two_arg_expression.rb', line 26

def equality_attributes
  %i[left_expr right_expr]
end