Class: PIECE::P

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#boardObject (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_hObject



34
35
36
# File 'lib/toychest/piece.rb', line 34

def to_h
	@h
end