Class: BagOfHolding::Dice::OperationResult
- Inherits:
-
Object
- Object
- BagOfHolding::Dice::OperationResult
- Defined in:
- lib/bag_of_holding/dice/operation_result.rb
Overview
Internal: Represent the results of an operation such as adding two dice pools.
Instance Attribute Summary collapse
-
#left_result ⇒ Object
Returns the value of attribute left_result.
-
#operation ⇒ Object
Returns the value of attribute operation.
-
#right_result ⇒ Object
Returns the value of attribute right_result.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(left_result: nil, right_result: nil, operation: nil, value: nil) ⇒ OperationResult
constructor
A new instance of OperationResult.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(left_result: nil, right_result: nil, operation: nil, value: nil) ⇒ OperationResult
Returns a new instance of OperationResult.
8 9 10 11 12 13 14 |
# File 'lib/bag_of_holding/dice/operation_result.rb', line 8 def initialize(left_result: nil, right_result: nil, operation: nil, value: nil) self.left_result = left_result self.right_result = right_result self.operation = operation self.value = value end |
Instance Attribute Details
#left_result ⇒ Object
Returns the value of attribute left_result.
6 7 8 |
# File 'lib/bag_of_holding/dice/operation_result.rb', line 6 def left_result @left_result end |
#operation ⇒ Object
Returns the value of attribute operation.
6 7 8 |
# File 'lib/bag_of_holding/dice/operation_result.rb', line 6 def operation @operation end |
#right_result ⇒ Object
Returns the value of attribute right_result.
6 7 8 |
# File 'lib/bag_of_holding/dice/operation_result.rb', line 6 def right_result @right_result end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/bag_of_holding/dice/operation_result.rb', line 6 def value @value end |
Instance Method Details
#==(other) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bag_of_holding/dice/operation_result.rb', line 24 def ==(other) begin return false unless left_result == other.left_result return false unless right_result == other.right_result return false unless operation == other.operation return false unless value == other.value rescue NoMethodError return false end true end |
#inspect ⇒ Object
20 21 22 |
# File 'lib/bag_of_holding/dice/operation_result.rb', line 20 def inspect "#{left_result.inspect} #{operation.operator} #{right_result.inspect}" end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/bag_of_holding/dice/operation_result.rb', line 16 def to_s "#{left_result} #{operation.operator} #{right_result}" end |