Class: Optimus::ParsedCalculator::Expr
- Inherits:
-
Object
- Object
- Optimus::ParsedCalculator::Expr
show all
- Defined in:
- lib/expression_parser/expressions.rb
Constant Summary
collapse
- BINARY_OPERATORS =
All of our literals, etc will ineherit from Expr. This will imbue them with the magic to work with our unary and binary operators.
[:+, :-, :*, :/, :%, :&, :>, :>=, :<, :<=]
Instance Method Summary
collapse
Instance Method Details
#-@ ⇒ Object
41
42
43
|
# File 'lib/expression_parser/expressions.rb', line 41
def -@
return PrefixExpr.new(:-, self)
end
|
#eq(other) ⇒ Object
32
33
34
|
# File 'lib/expression_parser/expressions.rb', line 32
def eq(other)
return BinaryExpr.new(self, "=".to_sym, other)
end
|
#logical_and(other) ⇒ Object
24
25
26
|
# File 'lib/expression_parser/expressions.rb', line 24
def logical_and(other)
return BinaryExpr.new(self, :and, other)
end
|
#logical_not ⇒ Object
45
46
47
|
# File 'lib/expression_parser/expressions.rb', line 45
def logical_not
return KeywordPrefixExpr.new(:not, self)
end
|
#logical_or(other) ⇒ Object
28
29
30
|
# File 'lib/expression_parser/expressions.rb', line 28
def logical_or(other)
return BinaryExpr.new(self, :or, other)
end
|
#neq(other) ⇒ Object
36
37
38
|
# File 'lib/expression_parser/expressions.rb', line 36
def neq(other)
return BinaryExpr.new(self, '!='.to_sym, other)
end
|
#to_bool(*args) ⇒ Object
49
50
51
52
53
|
# File 'lib/expression_parser/expressions.rb', line 49
def to_bool(*args)
val = evaluate(*args)
return false if val == ''
return val
end
|