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