Class: Optimus::ParsedCalculator::PrefixExpr

Inherits:
Expr
  • Object
show all
Includes:
Evaluators::Prefix
Defined in:
lib/expression_parser/expressions.rb

Direct Known Subclasses

KeywordPrefixExpr

Constant Summary

Constants included from Evaluators::Prefix

Evaluators::Prefix::Neg, Evaluators::Prefix::Not, Evaluators::Prefix::OpTable

Constants inherited from Expr

Expr::BINARY_OPERATORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Expr

#-@, #eq, #logical_and, #logical_not, #logical_or, #neq, #to_bool

Constructor Details

#initialize(op, right) ⇒ PrefixExpr

Returns a new instance of PrefixExpr.



80
81
82
83
# File 'lib/expression_parser/expressions.rb', line 80

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

Instance Attribute Details

#opObject (readonly)

Returns the value of attribute op.



79
80
81
# File 'lib/expression_parser/expressions.rb', line 79

def op
  @op
end

#rightObject (readonly)

Returns the value of attribute right.



79
80
81
# File 'lib/expression_parser/expressions.rb', line 79

def right
  @right
end

Instance Method Details

#evaluate(*args) ⇒ Object



89
90
91
92
# File 'lib/expression_parser/expressions.rb', line 89

def evaluate(*args)
  rval = @right.evaluate(*args)
  return OpTable[@op].call(rval)
end

#to_sObject



85
86
87
# File 'lib/expression_parser/expressions.rb', line 85

def to_s
  "#{@op}(#{@right})"
end