Class: TwistyPuzzles::FakeCommutator

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

Overview

Algorithm that is used like a commutator but actually isn’t one.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Commutator

#cancellations

Constructor Details

#initialize(algorithm) ⇒ FakeCommutator

Returns a new instance of FakeCommutator.

Raises:

  • (TypeError)


21
22
23
24
25
26
# File 'lib/twisty_puzzles/commutator.rb', line 21

def initialize(algorithm)
  raise TypeError unless algorithm.is_a?(Algorithm)

  super()
  @algorithm = algorithm
end

Instance Attribute Details

#algorithmObject (readonly)

Returns the value of attribute algorithm.



28
29
30
# File 'lib/twisty_puzzles/commutator.rb', line 28

def algorithm
  @algorithm
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


30
31
32
# File 'lib/twisty_puzzles/commutator.rb', line 30

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

#hashObject



36
37
38
# File 'lib/twisty_puzzles/commutator.rb', line 36

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

#inverseObject



40
41
42
# File 'lib/twisty_puzzles/commutator.rb', line 40

def inverse
  FakeCommutator.new(@algorithm.inverse)
end

#to_sObject



44
45
46
# File 'lib/twisty_puzzles/commutator.rb', line 44

def to_s
  @algorithm.to_s
end