ruby-forum.com
20 May '12, 7am
@ponnappa yeah I understood blocks and yield too.. this helped in understanding too
Alle mercoledì 28 gennaio 2009, klochner ha scritto: > > than return, but I don't consider this to be one of them. Anyone care > to weigh in? yield and return do completely different things, and you can't use one in place of the other. return tells ruby to stop executing the method and return its argument to the caller. yield tells ruby to call the block passed to the method, giving it its argument. yield will produce an error if the method wasn't called with a block: def test_yield yield 43 end test_yield # notice that no block was passed to the method => LocalJumpError: no block given In ruby, there's no need to put a return at the end of a method, as the method will always return the value of the last expression. This means that a method defined this way: def test_return return 4 end will give exactly the same result as a method defined this way: def test_no_return 4 en...
Full article:
http://www.ruby-forum.com/topic/177007