Rajiv Kumar ha scritto:
> hii,
> I am not understanding about the ruby blocks. how to pass them as
> parameters and also the yield() method is not clear..
Hi,
the yield() method executes the passed block in the method called: think
about it as a placeholder for the block passed.
For example, if you define a method like this
def test
yield
end
you can call the method with a block attached to it: test { puts "Hi!" }.
Remember that when you invoke a method, you can always attach a block to
it. The standard syntax is
method(param_1, param_2, ..., param_n) { block }
Obviously you can pass some parameters to the yield() method: those
parameters will be forwarded to the block
def test(name)
yield(name)
end
test("Andrea") { |name| puts "Hi, #{name}!" }
|name| means: this block accepts a parameter called "name". yield() will
pass the parameter to the block.
Andrea.
p.s.: sorry for the poor english
--
** http://emptylist.wordpress.com
** Think about the environment before printing
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
ruby-on-rails-programming-with-passion-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---