Class: TwistyPuzzles::CommutatorSequence
- Inherits:
-
Commutator
- Object
- Commutator
- TwistyPuzzles::CommutatorSequence
- Defined in:
- lib/twisty_puzzles/commutator.rb
Overview
A commutator sequence of the form [A, B] + [C, D].
Instance Attribute Summary collapse
-
#commutators ⇒ Object
readonly
Returns the value of attribute commutators.
Instance Method Summary collapse
- #algorithm ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(commutators) ⇒ CommutatorSequence
constructor
A new instance of CommutatorSequence.
- #inverse ⇒ Object
- #to_s ⇒ Object
Methods inherited from Commutator
Constructor Details
#initialize(commutators) ⇒ CommutatorSequence
Returns a new instance of CommutatorSequence.
51 52 53 54 55 56 |
# File 'lib/twisty_puzzles/commutator.rb', line 51 def initialize(commutators) raise TypeError unless commutators.is_a?(Array) && commutators.all?(Commutator) super() @commutators = commutators end |
Instance Attribute Details
#commutators ⇒ Object (readonly)
Returns the value of attribute commutators.
58 59 60 |
# File 'lib/twisty_puzzles/commutator.rb', line 58 def commutators @commutators end |
Instance Method Details
#algorithm ⇒ Object
78 79 80 |
# File 'lib/twisty_puzzles/commutator.rb', line 78 def algorithm @commutators.sum(Algorithm.empty, &:algorithm) end |
#eql?(other) ⇒ Boolean Also known as: ==
60 61 62 |
# File 'lib/twisty_puzzles/commutator.rb', line 60 def eql?(other) self.class.equal?(other.class) && @commutators == other.commutators end |
#hash ⇒ Object
66 67 68 |
# File 'lib/twisty_puzzles/commutator.rb', line 66 def hash @hash ||= [self.class, @commutators].hash end |
#inverse ⇒ Object
70 71 72 |
# File 'lib/twisty_puzzles/commutator.rb', line 70 def inverse CommutatorSequence.new(@commutators.map(&:inverse).reverse) end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/twisty_puzzles/commutator.rb', line 74 def to_s @commutators.join(' + ') end |