Class: Rjq::AST::BinaryOp

Inherits:
Node
  • Object
show all
Defined in:
lib/rjq/ast.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#source_span

Instance Method Summary collapse

Methods inherited from Node

#assign_value, #invalid_path_message, #paths, #take, #with_source_span

Constructor Details

#initialize(left, op, right) ⇒ BinaryOp

Returns a new instance of BinaryOp.



816
817
818
819
820
# File 'lib/rjq/ast.rb', line 816

def initialize(left, op, right)
  @left = left
  @op = op
  @right = right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



814
815
816
# File 'lib/rjq/ast.rb', line 814

def left
  @left
end

#opObject (readonly)

Returns the value of attribute op.



814
815
816
# File 'lib/rjq/ast.rb', line 814

def op
  @op
end

#rightObject (readonly)

Returns the value of attribute right.



814
815
816
# File 'lib/rjq/ast.rb', line 814

def right
  @right
end

Instance Method Details

#eval(input, context) ⇒ Object



822
823
824
825
826
827
828
829
830
831
# File 'lib/rjq/ast.rb', line 822

def eval(input, context)
  return eval_alternative(input, context) if @op == '//'
  return eval_boolean(input, context) if @op == 'and' || @op == 'or'

  left_values = @left.eval(input, context)
  right_values = @right.eval(input, context)
  left_values.flat_map do |left|
    right_values.map { |right| apply(left, right) }
  end
end