From: "Gulyás Attila" Date: 2013-04-16T13:21:15+09:00 Subject: Re: Trying to understand blocks --089e01161a9060648804da729e8c Content-Type: text/plain; charset=UTF-8 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 wrote: > http://codelikethis.com/lessons/ruby_blocks/blocks 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 > > --089e01161a9060648804da729e8c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Hi,

I found this very helpful:

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

Best regards
Attila

On Sat, Apr 13, 2013 at 1:42 AM, A= lex Chaffee <alex@stinky.com> wrote:
http://codelikethis.com/lessons/ruby_blocks/blocks 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)
=C2=A0 p.call("Jim")
end

def bar
=C2=A0 =C2=A0baz =3D lambda { |n| n.upcase }
=C2=A0 =C2=A0foo(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.)

=C2=A0- A


--089e01161a9060648804da729e8c--