Method: JustChess::SquareSet#initialize
- Defined in:
- lib/just_chess/square_set.rb
#initialize(squares:) ⇒ SquareSet
New objects can be instantiated by passing in a hash with squares. They can be square objects or hashes.
Example:
# Instantiates a new Square Set
JustChess::SquareSet.new({
squares: [
{ x: 1, y: 0, piece: { player_number: 1, direction: 1, king: false }}
]
})
24 25 26 27 28 29 30 31 32 |
# File 'lib/just_chess/square_set.rb', line 24 def initialize(squares: ) @squares = if squares.all? { |s| s.instance_of?(Hash) } squares.map { |s| Square.new(**s) } elsif squares.all? { |s| s.instance_of?(Square) } squares else raise ArgumentError, "all squares must have the same class" end end |