BLOCKS:
http://stackoverflow.com/questions/814739/whats-this-block-in-ruby-and-how-does-it-get-passes-in-a-method-here
Idiomatic & Non-idiomatic ways of having CALLBACKS in RUBY:
http://stackoverflow.com/questions/1677861/how-to-implement-a-callback-in-ruby
http://stackoverflow.com/questions/814739/whats-this-block-in-ruby-and-how-does-it-get-passes-in-a-method-here
BLOCKS are a fairly basic part of ruby. They're delimited by either:
do |arg0,arg1| ... end
or
{ |arg0,arg1,arg2| ... }
.
They allow you to specify a CALLBACK to pass to a METHOD.
This CALLBACK can be invoked in two ways - either by capturing it by specifying a final ARGUMENT prefixed withCALLBACKS:&
, or by using theyield
keyword
Idiomatic & Non-idiomatic ways of having CALLBACKS in RUBY:
http://stackoverflow.com/questions/1677861/how-to-implement-a-callback-in-ruby
The idiomatic approach would be to pass a BLOCK instead of a REFERENCE to a METHOD. One advantage a BLOCK has over a freestanding METHOD is CONTEXT - a BLOCK is a CLOSURE, so it can refer to variables from the SCOPE in which it was declared. This cuts down on the number of PARAMETERS do_stuff needs to pass to the --CALLBACK.
No comments:
Post a Comment