Class: Fragment
Overview
An expression fragment. An expression can consist of many fragments.
Instance Attribute Summary collapse
-
#lv ⇒ Object
Returns the value of attribute lv.
-
#operand ⇒ Object
Returns the value of attribute operand.
Instance Method Summary collapse
- #*(value) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #evaluate ⇒ Object
-
#initialize(lv, operand) ⇒ Fragment
constructor
A new instance of Fragment.
- #to_s ⇒ Object
- #variable ⇒ Object
Constructor Details
#initialize(lv, operand) ⇒ Fragment
Returns a new instance of Fragment.
62 63 64 65 |
# File 'lib/rulp/expression.rb', line 62 def initialize(lv, operand) @lv = lv @operand = operand end |
Instance Attribute Details
#lv ⇒ Object
Returns the value of attribute lv.
60 61 62 |
# File 'lib/rulp/expression.rb', line 60 def lv @lv end |
#operand ⇒ Object
Returns the value of attribute operand.
60 61 62 |
# File 'lib/rulp/expression.rb', line 60 def operand @operand end |
Instance Method Details
#*(value) ⇒ Object
75 76 77 |
# File 'lib/rulp/expression.rb', line 75 def *(value) Fragment.new(@lv, @operand * value) end |
#+(other) ⇒ Object
67 68 69 |
# File 'lib/rulp/expression.rb', line 67 def +(other) return Expressions.new([self] + Expressions[other].expressions) end |
#-(other) ⇒ Object
71 72 73 |
# File 'lib/rulp/expression.rb', line 71 def -(other) self.+(-other) end |
#-@ ⇒ Object
87 88 89 90 |
# File 'lib/rulp/expression.rb', line 87 def -@ @operand = -@operand self end |
#evaluate ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/rulp/expression.rb', line 79 def evaluate if [TrueClass,FalseClass].include? @lv.value.class @operand * (@lv.value ? 1 : 0) else @operand * @lv.value end end |
#to_s ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rulp/expression.rb', line 102 def to_s case @operand when -1 "-#{@lv}" when 1 "#{@lv}" else "#{@operand} #{@lv}" end end |
#variable ⇒ Object
92 93 94 |
# File 'lib/rulp/expression.rb', line 92 def variable @lv end |