Class: BOARD::B::C

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(k, c) ⇒ C

Returns a new instance of C.



16
17
18
19
20
# File 'lib/toychest/board.rb', line 16

def initialize k, c
  @board, @cell = k, c
  @h = {}
  @on = {}
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



15
16
17
# File 'lib/toychest/board.rb', line 15

def board
  @board
end

Instance Method Details

#[](k) ⇒ Object



21
22
23
# File 'lib/toychest/board.rb', line 21

def [] k
  @h[k]
end

#[]=(k, v) ⇒ Object



24
25
26
# File 'lib/toychest/board.rb', line 24

def []= k,v
  @h[k] = v
end

#on(k, h = {}, &b) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/toychest/board.rb', line 27

def on k, h={}, &b
  if block_given?
    @on[k] = b
  else
    if @on.has_key? k
      @on[k].call(self, k, h)
    else
      if BOARD.on.has_key? k
        BOARD.on[k].call(self, k, h)
      else
        BOARD.on[:default].call(self, k, h)
      end
    end
  end
end

#to_hObject



42
43
44
# File 'lib/toychest/board.rb', line 42

def to_h
  @h
end