Class: GridCLI::Hooker
- Inherits:
-
Object
- Object
- GridCLI::Hooker
- Defined in:
- lib/gridcli/hooks.rb
Instance Method Summary collapse
-
#initialize ⇒ Hooker
constructor
A new instance of Hooker.
- #invoke(name, arg = nil) ⇒ Object
- #register(name, &method) ⇒ Object
Constructor Details
#initialize ⇒ Hooker
Returns a new instance of Hooker.
3 4 5 |
# File 'lib/gridcli/hooks.rb', line 3 def initialize @hooks = {} end |
Instance Method Details
#invoke(name, arg = nil) ⇒ Object
11 12 13 |
# File 'lib/gridcli/hooks.rb', line 11 def invoke(name, arg=nil) @hooks.fetch(name, []).inject(arg) { |params,proc| proc.call(params) } end |
#register(name, &method) ⇒ Object
7 8 9 |
# File 'lib/gridcli/hooks.rb', line 7 def register(name, &method) @hooks[name] = @hooks.fetch(name, []) + [method] end |