Class: BagOfHolding::Dice::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/bag_of_holding/dice/operation.rb

Overview

Internal: Encapsulates an operation such as adding two dice pools

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left: nil, right: nil) ⇒ Operation

Returns a new instance of Operation.



7
8
9
10
# File 'lib/bag_of_holding/dice/operation.rb', line 7

def initialize(left: nil, right: nil)
  self.left = left
  self.right = right
end

Instance Attribute Details

#leftObject

Returns the value of attribute left.



5
6
7
# File 'lib/bag_of_holding/dice/operation.rb', line 5

def left
  @left
end

#rightObject

Returns the value of attribute right.



5
6
7
# File 'lib/bag_of_holding/dice/operation.rb', line 5

def right
  @right
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/bag_of_holding/dice/operation.rb', line 19

def ==(other)
  begin
    return false unless left == other.left
    return false unless right == other.right
  rescue NoMethodError
    return false
  end

  true
end

#rollObject



12
13
14
15
16
17
# File 'lib/bag_of_holding/dice/operation.rb', line 12

def roll
  BagOfHolding::Dice::OperationResult.new left_result: left_result,
                                          right_result: right_result,
                                          operation: self,
                                          value: value
end