Class: Mastermind::Game::Piece
- Inherits:
-
Object
- Object
- Mastermind::Game::Piece
- Defined in:
- lib/mastermind/game/piece.rb
Constant Summary collapse
- COLORS =
[:red, :green, :blue, :yellow, :white, :black]
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
Instance Method Summary collapse
- #==(piece) ⇒ Object
-
#initialize(color: COLORS.sample) ⇒ Piece
constructor
A new instance of Piece.
Constructor Details
#initialize(color: COLORS.sample) ⇒ Piece
Returns a new instance of Piece.
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
#color ⇒ Object (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 |