Class: Opt::Product

Inherits:
Expression show all
Defined in:
lib/opt/product.rb

Instance Attribute Summary collapse

Attributes inherited from Expression

#parts

Instance Method Summary collapse

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

#leftObject (readonly)

Returns the value of attribute left.



3
4
5
# File 'lib/opt/product.rb', line 3

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



3
4
5
# File 'lib/opt/product.rb', line 3

def right
  @right
end

Instance Method Details

#inspectObject



10
11
12
# File 'lib/opt/product.rb', line 10

def inspect
  "#{inspect_part(@left)} * #{inspect_part(@right)}"
end

#valueObject



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

#varsObject



20
21
22
# File 'lib/opt/product.rb', line 20

def vars
  @vars ||= (@left.vars + @right.vars).uniq
end