Class: PIECE::P
- Inherits:
-
Object
- Object
- PIECE::P
- Defined in:
- lib/toychest/piece.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
-
#initialize(k) ⇒ P
constructor
A new instance of P.
- #on(k, h = {}, &b) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(k) ⇒ P
Returns a new instance of P.
8 9 10 11 12 |
# File 'lib/toychest/piece.rb', line 8 def initialize k @board = k @h = {} @on = {} end |
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
7 8 9 |
# File 'lib/toychest/piece.rb', line 7 def board @board end |
Instance Method Details
#[](k) ⇒ Object
13 14 15 |
# File 'lib/toychest/piece.rb', line 13 def [] k @h[k] end |
#[]=(k, v) ⇒ Object
16 17 18 |
# File 'lib/toychest/piece.rb', line 16 def []= k,v @h[k] = v end |
#on(k, h = {}, &b) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/toychest/piece.rb', line 19 def on k, h={}, &b if block_given? @on[k] = b else if @on.has_key? k return @on[k].call(self, k, h) else if PIECE.on.has_key? k return PIECE.on[k].call(self, k, h) else return PIECE.on[:default].call(self, k, h) end end end end |
#to_h ⇒ Object
34 35 36 |
# File 'lib/toychest/piece.rb', line 34 def to_h @h end |