Class: Mastermind::Game::Piece

Inherits:
Object
  • Object
show all
Defined in:
lib/mastermind/game/piece.rb

Constant Summary collapse

COLORS =
[:red, :green, :blue, :yellow, :white, :black]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color: COLORS.sample) ⇒ Piece

Returns a new instance of Piece.

Raises:

  • (ArgumentError)


8
9
10
11
# File 'lib/mastermind/game/piece.rb', line 8

def initialize(color: COLORS.sample)
  raise ArgumentError.new("Invalid color: #{color}.") unless COLORS.include?(color)
  @color = color
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



6
7
8
# File 'lib/mastermind/game/piece.rb', line 6

def color
  @color
end

Instance Method Details

#==(piece) ⇒ Object



13
14
15
# File 'lib/mastermind/game/piece.rb', line 13

def ==(piece)
  piece.is_a?(Piece) && color == piece.color
end