The basic idea here is to have your callbacks setup through a method call and not sent as an argument to the method. You can then have these callbacks adapt depending on the other parameters sent through the method. After the method had been executed, it is deleted from the hash.
class Test
def setup_callbacks
callback.hello do |string|
puts string
end
end
def request
setup_callbacks
callback.hello('Hello World')
end
end
Test.new.request
@JEG2
yep it is per object mostly making the callback available to the whole object to execute* -- That's why the name ;)
@rogerbraun
Because you might have other methods using the same key to call a block
(since if the key exists, it would simply return the block and not assign a new one)
but it would be best to have it different to avoid executing the wrong code*
@jeremyevans
hmmm, it actually depends, I wanted to try not passing anything at all and I was coming from the idea that the end goal was simply to be able to call your callbacks in your method. Which in turn is the reason for passing multiple blocks to the method -- which I tried to eliminate. ;)