Class: FExpr::Evaluator::OpNode
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#op ⇒ Object
readonly
Returns the value of attribute op.
Instance Method Summary collapse
- #eval ⇒ Object
-
#initialize(op, a, b) ⇒ OpNode
constructor
A new instance of OpNode.
- #to_string(n) ⇒ Object
Methods inherited from Node
Constructor Details
#initialize(op, a, b) ⇒ OpNode
Returns a new instance of OpNode.
41 42 43 44 45 |
# File 'lib/fexpr/base.rb', line 41 def initialize(op,a,b) @op = op @a = a @b = b end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
40 41 42 |
# File 'lib/fexpr/base.rb', line 40 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
40 41 42 |
# File 'lib/fexpr/base.rb', line 40 def b @b end |
#op ⇒ Object (readonly)
Returns the value of attribute op.
40 41 42 |
# File 'lib/fexpr/base.rb', line 40 def op @op end |
Instance Method Details
#eval ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fexpr/base.rb', line 46 def eval a = @a.eval b = @b.eval case @op when '|' then a and a != 0 ? a : b when '&' then (a and a!=0 and b and b!=0) ? a : 0 when '=' then a == b when '>' then a > b when '>=' then a >= b when '<' then a < b when '<=' then a <= b when '!=' then a != b when '+' then a + b when '-' then a - b when '*' then a * b when 'x' then a * b when '/' then a / b when '%' then a.to_i % b.to_i else error 'Invalid operator \'' + @op + '\'' end end |
#to_string(n) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/fexpr/base.rb', line 67 def to_string(n) str = x(n) + @op + "\n" str += a.to_string(n+1) + "\n" str += b.to_string(n+1) return str end |