Class: TwistyPuzzles::PureCommutator

Inherits:
Commutator show all
Defined in:
lib/twisty_puzzles/commutator.rb

Overview

Pure commutator of the form A B A’ B’.

Direct Known Subclasses

SlashCommutator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Commutator

#cancellations

Constructor Details

#initialize(first_part, second_part) ⇒ PureCommutator

Returns a new instance of PureCommutator.

Raises:

  • (TypeError)


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_partObject (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_partObject (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

#algorithmObject



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: ==

Returns:

  • (Boolean)


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

#hashObject



103
104
105
# File 'lib/twisty_puzzles/commutator.rb', line 103

def hash
  @hash ||= [self.class, @first_part, @second_part].hash
end

#inverseObject



107
108
109
# File 'lib/twisty_puzzles/commutator.rb', line 107

def inverse
  PureCommutator.new(second_part, first_part)
end

#to_sObject



111
112
113
# File 'lib/twisty_puzzles/commutator.rb', line 111

def to_s
  "[#{@first_part}, #{@second_part}]"
end