Class: JustBackgammon::Piece

Inherits:
Object
  • Object
show all
Extended by:
Common
Defined in:
lib/just_backgammon/piece.rb

Overview

Piece

A piece owned by a player that moves around the board.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

load

Constructor Details

#initialize(owner:) ⇒ Piece

A new instance of Piece.

Example:

# Instantiates a new Piece
JustBackgammon::Piece.new(1)

Parameters:

  • owner (Fixnum)

    The owner of the piece.



19
20
21
# File 'lib/just_backgammon/piece.rb', line 19

def initialize(owner:)
  @owner = owner
end

Instance Attribute Details

#ownerFixnum (readonly)

Returns the owner of the piece.

Returns:

  • (Fixnum)

    the owner of the piece



24
25
26
# File 'lib/just_backgammon/piece.rb', line 24

def owner
  @owner
end

Instance Method Details

#as_jsonHash

A hashed serialized representation of the piece.

Returns:

  • (Hash)


29
30
31
# File 'lib/just_backgammon/piece.rb', line 29

def as_json
  { owner: owner }
end