Class: BagOfHolding::Dice::OperationResult

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_resultObject

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

#operationObject

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_resultObject

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

#valueObject

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

#inspectObject



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_sObject



16
17
18
# File 'lib/bag_of_holding/dice/operation_result.rb', line 16

def to_s
  "#{left_result} #{operation.operator} #{right_result}"
end