Class: TwistyPuzzles::PureCommutator
- Inherits:
-
Commutator
- Object
- Commutator
- TwistyPuzzles::PureCommutator
- Defined in:
- lib/twisty_puzzles/commutator.rb
Overview
Pure commutator of the form A B A’ B’.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#first_part ⇒ Object
readonly
Returns the value of attribute first_part.
-
#second_part ⇒ Object
readonly
Returns the value of attribute second_part.
Instance Method Summary collapse
- #algorithm ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(first_part, second_part) ⇒ PureCommutator
constructor
A new instance of PureCommutator.
- #inverse ⇒ Object
- #to_s ⇒ Object
Methods inherited from Commutator
Constructor Details
#initialize(first_part, second_part) ⇒ PureCommutator
Returns a new instance of PureCommutator.
85 86 87 88 89 90 91 92 |
# File 'lib/twisty_puzzles/commutator.rb', line 85 def initialize(first_part, second_part) raise TypeError unless first_part.is_a?(Algorithm) raise TypeError unless second_part.is_a?(Algorithm) super() @first_part = first_part @second_part = second_part end |
Instance Attribute Details
#first_part ⇒ Object (readonly)
Returns the value of attribute first_part.
94 95 96 |
# File 'lib/twisty_puzzles/commutator.rb', line 94 def first_part @first_part end |
#second_part ⇒ Object (readonly)
Returns the value of attribute second_part.
94 95 96 |
# File 'lib/twisty_puzzles/commutator.rb', line 94 def second_part @second_part end |
Instance Method Details
#algorithm ⇒ Object
115 116 117 |
# File 'lib/twisty_puzzles/commutator.rb', line 115 def algorithm first_part + second_part + first_part.inverse + second_part.inverse end |
#eql?(other) ⇒ Boolean Also known as: ==
96 97 98 99 |
# File 'lib/twisty_puzzles/commutator.rb', line 96 def eql?(other) self.class.equal?(other.class) && @first_part == other.first_part && @second_part == other.second_part end |
#hash ⇒ Object
103 104 105 |
# File 'lib/twisty_puzzles/commutator.rb', line 103 def hash @hash ||= [self.class, @first_part, @second_part].hash end |
#inverse ⇒ Object
107 108 109 |
# File 'lib/twisty_puzzles/commutator.rb', line 107 def inverse PureCommutator.new(second_part, first_part) end |
#to_s ⇒ Object
111 112 113 |
# File 'lib/twisty_puzzles/commutator.rb', line 111 def to_s "[#{@first_part}, #{@second_part}]" end |