Class: BagOfHolding::Dice::Operation
- Inherits:
-
Object
- Object
- BagOfHolding::Dice::Operation
- Defined in:
- lib/bag_of_holding/dice/operation.rb
Overview
Internal: Encapsulates an operation such as adding two dice pools
Direct Known Subclasses
AdditionOperation, DivisionOperation, MultiplicationOperation, SubtractionOperation
Instance Attribute Summary collapse
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(left: nil, right: nil) ⇒ Operation
constructor
A new instance of Operation.
- #roll ⇒ Object
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
#left ⇒ Object
Returns the value of attribute left.
5 6 7 |
# File 'lib/bag_of_holding/dice/operation.rb', line 5 def left @left end |
#right ⇒ Object
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 |
#roll ⇒ Object
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 |