Class: Clemency::Callbacks
- Inherits:
-
Object
- Object
- Clemency::Callbacks
- Defined in:
- lib/clemency/callbacks.rb
Instance Method Summary collapse
- #call!(key, *args) ⇒ Object
- #get(key) ⇒ Object
-
#initialize ⇒ Callbacks
constructor
A new instance of Callbacks.
- #set(key, callback) ⇒ Object
Constructor Details
#initialize ⇒ Callbacks
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 |