Class: TwistyPuzzles::SetupCommutator
- Inherits:
-
Commutator
- Object
- Commutator
- TwistyPuzzles::SetupCommutator
- Defined in:
- lib/twisty_puzzles/commutator.rb
Overview
Setup commutator of the form A B A’.
Instance Attribute Summary collapse
-
#inner_commutator ⇒ Object
readonly
Returns the value of attribute inner_commutator.
-
#setup ⇒ Object
readonly
Returns the value of attribute setup.
Instance Method Summary collapse
- #algorithm ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(setup, inner_commutator) ⇒ SetupCommutator
constructor
A new instance of SetupCommutator.
- #inverse ⇒ Object
- #to_s ⇒ Object
Methods inherited from Commutator
Constructor Details
#initialize(setup, inner_commutator) ⇒ SetupCommutator
Returns a new instance of SetupCommutator.
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/twisty_puzzles/commutator.rb', line 137 def initialize(setup, inner_commutator) raise TypeError, 'Setup move has to be an algorithm.' unless setup.is_a?(Algorithm) unless inner_commutator.is_a?(Commutator) raise TypeError, 'Inner commutator has to be a commutator.' end super() @setup = setup @inner_commutator = inner_commutator end |
Instance Attribute Details
#inner_commutator ⇒ Object (readonly)
Returns the value of attribute inner_commutator.
148 149 150 |
# File 'lib/twisty_puzzles/commutator.rb', line 148 def inner_commutator @inner_commutator end |
#setup ⇒ Object (readonly)
Returns the value of attribute setup.
148 149 150 |
# File 'lib/twisty_puzzles/commutator.rb', line 148 def setup @setup end |
Instance Method Details
#algorithm ⇒ Object
169 170 171 |
# File 'lib/twisty_puzzles/commutator.rb', line 169 def algorithm setup + inner_commutator.algorithm + setup.inverse end |
#eql?(other) ⇒ Boolean Also known as: ==
150 151 152 153 |
# File 'lib/twisty_puzzles/commutator.rb', line 150 def eql?(other) self.class.equal?(other.class) && @setup == other.setup && @inner_commutator == other.inner_commutator end |
#hash ⇒ Object
157 158 159 |
# File 'lib/twisty_puzzles/commutator.rb', line 157 def hash @hash ||= [self.class, @setup, @inner_commutator].hash end |
#inverse ⇒ Object
161 162 163 |
# File 'lib/twisty_puzzles/commutator.rb', line 161 def inverse SetupCommutator.new(setup, @inner_commutator.inverse) end |
#to_s ⇒ Object
165 166 167 |
# File 'lib/twisty_puzzles/commutator.rb', line 165 def to_s "[#{@setup} : #{@inner_commutator}]" end |