Class: TwistyPuzzles::CommutatorSequence

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

Overview

A commutator sequence of the form [A, B] + [C, D].

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Commutator

#cancellations

Constructor Details

#initialize(commutators) ⇒ CommutatorSequence

Returns a new instance of CommutatorSequence.

Raises:

  • (TypeError)


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

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

#algorithmObject



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

Returns:

  • (Boolean)


60
61
62
# File 'lib/twisty_puzzles/commutator.rb', line 60

def eql?(other)
  self.class.equal?(other.class) && @commutators == other.commutators
end

#hashObject



66
67
68
# File 'lib/twisty_puzzles/commutator.rb', line 66

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

#inverseObject



70
71
72
# File 'lib/twisty_puzzles/commutator.rb', line 70

def inverse
  CommutatorSequence.new(@commutators.map(&:inverse).reverse)
end

#to_sObject



74
75
76
# File 'lib/twisty_puzzles/commutator.rb', line 74

def to_s
  @commutators.join(' + ')
end