Code block vs

2 views
Skip to first unread message

Saifi Khan

unread,
Feb 27, 2009, 6:44:24 AM2/27/09
to rub...@googlegroups.com
Hi all:

How is a code block in Ruby different from a 'inner class' in
Java ?


thanks
Saifi.

suman karthik

unread,
Feb 27, 2009, 4:28:14 AM2/27/09
to rub...@googlegroups.com
In Ruby, a code block (or just "Block") is an object that contains some Ruby code, and the context necessary to execute it. Code blocks are the most visually distinctive aspect of Ruby, and also one of the most confusing to newcomers from other languages. Essentially, a Ruby code block is a method that has no name. Most other languages have something like a Ruby code block: C's function pointers, C++'s function objects, Python's lambdas and list comprehensions, Perl's anonymous functions, Java's anonymous inner classes. These features live mostly in the corners of those languages, shunned by novice programmers. Ruby can't be written without code blocks. Of the major languages, only Lisp is more block-oriented.

Copy pasted.
--
-Suman
http://www.zerocaffe.in

Saifi Khan

unread,
Feb 27, 2009, 10:37:16 AM2/27/09
to rub...@googlegroups.com
On Fri, 27 Feb 2009, suman karthik wrote:

>
> Essentially, a Ruby code block is a method that has no name.
>

This sounds like an 'anonmyous delegate'.

What is the best approach to reason about the scope of code
block ?


thanks
Saifi.

suman karthik

unread,
Feb 27, 2009, 5:08:01 AM2/27/09
to rub...@googlegroups.com
Better minds have been banging their heads together debating ruby's blocks, lambdas and proc for 1.9 and 2.0.

I haven't exactly been in the loop.
--
-Suman
http://www.zerocaffe.in
Reply all
Reply to author
Forward
0 new messages