Class: TwistyPuzzles::SetupCommutator

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

Overview

Setup commutator of the form A B A’.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Commutator

#cancellations

Constructor Details

#initialize(setup, inner_commutator) ⇒ SetupCommutator

Returns a new instance of SetupCommutator.

Raises:

  • (TypeError)


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

#setupObject (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

#algorithmObject



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

Returns:

  • (Boolean)


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

#hashObject



157
158
159
# File 'lib/twisty_puzzles/commutator.rb', line 157

def hash
  @hash ||= [self.class, @setup, @inner_commutator].hash
end

#inverseObject



161
162
163
# File 'lib/twisty_puzzles/commutator.rb', line 161

def inverse
  SetupCommutator.new(setup, @inner_commutator.inverse)
end

#to_sObject



165
166
167
# File 'lib/twisty_puzzles/commutator.rb', line 165

def to_s
  "[#{@setup} : #{@inner_commutator}]"
end