Class: Saxxy::CallbackArray

Inherits:
Array
  • Object
show all
Defined in:
lib/saxxy/utils/callback_array.rb

Instance Method Summary collapse

Instance Method Details

#<<(obj) ⇒ Object


4
5
6
7
8
# File 'lib/saxxy/utils/callback_array.rb', line 4

def <<(obj)
  super(obj)
  @add_callback.call(obj) if @add_callback
  self
end

#>>(obj) ⇒ Object


10
11
12
13
14
# File 'lib/saxxy/utils/callback_array.rb', line 10

def >>(obj)
  delete(obj)
  @remove_callback.call(obj) if @remove_callback
  self
end

#on_add(&block) ⇒ Object


21
22
23
24
# File 'lib/saxxy/utils/callback_array.rb', line 21

def on_add(&block)
  @add_callback = block
  self
end

#on_remove(&block) ⇒ Object


16
17
18
19
# File 'lib/saxxy/utils/callback_array.rb', line 16

def on_remove(&block)
  @remove_callback = block
  self
end