Class: Opt::Product
- Inherits:
-
Expression
- Object
- Expression
- Opt::Product
- Defined in:
- lib/opt/product.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Attributes inherited from Expression
Instance Method Summary collapse
-
#initialize(left, right) ⇒ Product
constructor
A new instance of Product.
- #inspect ⇒ Object
- #value ⇒ Object
- #vars ⇒ Object
Methods inherited from Expression
#*, #+, #-, #-@, #<, #<=, #==, #>, #>=, #coerce, to_expression
Constructor Details
#initialize(left, right) ⇒ Product
Returns a new instance of Product.
5 6 7 8 |
# File 'lib/opt/product.rb', line 5 def initialize(left, right) @left = left @right = right end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
3 4 5 |
# File 'lib/opt/product.rb', line 3 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
3 4 5 |
# File 'lib/opt/product.rb', line 3 def right @right end |
Instance Method Details
#inspect ⇒ Object
10 11 12 |
# File 'lib/opt/product.rb', line 10 def inspect "#{inspect_part(@left)} * #{inspect_part(@right)}" end |
#value ⇒ Object
14 15 16 17 18 |
# File 'lib/opt/product.rb', line 14 def value return nil if left.value.nil? || right.value.nil? left.value * right.value end |
#vars ⇒ Object
20 21 22 |
# File 'lib/opt/product.rb', line 20 def vars @vars ||= (@left.vars + @right.vars).uniq end |