Trying to understand blocks

Hi,

I found this very helpful:
http://innig.net/software/ruby/closures-in-ruby

As the name suggests it is mainly about closures but still.

Best regards
Attila

···

On Sat, Apr 13, 2013 at 1:42 AM, Alex Chaffee <alex@stinky.com> wrote:

Blocks - Code Like This has slides and a
video lecture that might help you out.

Basically, yield is calling an anonymous, invisible function pointer.
It's sort of like

def foo(p)
  p.call("Jim")
end

def bar
   baz = lambda { |n| n.upcase }
   foo(baz)
end

The & turns a proc into a block and back again.

It's one of the oddest parts of Ruby and it's almost (but not
entirely) syntactic sugar so you can use "do" blocks to make your code
look cool. (Not a dis: I think it's great, but it is confusing.)

- A

Excellent one this is!

Thank you very much to share it.

···

--
Posted via http://www.ruby-forum.com/.