Class: Clemency::Callbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/clemency/callbacks.rb

Instance Method Summary collapse

Constructor Details

#initializeCallbacks

Returns a new instance of Callbacks.



5
6
7
# File 'lib/clemency/callbacks.rb', line 5

def initialize
  @callbacks = {}
end

Instance Method Details

#call!(key, *args) ⇒ Object



9
10
11
# File 'lib/clemency/callbacks.rb', line 9

def call!(key, *args)
  get(key).call(*args)
end

#get(key) ⇒ Object



13
14
15
# File 'lib/clemency/callbacks.rb', line 13

def get(key)
  @callbacks.fetch(key, Proc.new {})
end

#set(key, callback) ⇒ Object



17
18
19
# File 'lib/clemency/callbacks.rb', line 17

def set(key, callback)
  @callbacks[key] = callback
end