I'm confused with block in ruby, compared to smalltalk.

Posted by weakish on Stack Overflow See other posts from Stack Overflow or by weakish
Published on 2010-06-06T10:42:54Z Indexed on 2010/06/06 10:52 UTC
Read the original article Hit count: 246

Filed under:
|
|

What does block in ruby mean? It looks similar with smalltalk, but you can't send messages to it.

For example, in smalltalk:

[:x | x + 3] value: 3

returns 6. But in ruby:

{|x| x + 3}.call 3

will cause SyntaxError.

Well, you can pass messages to lambda in ruby, though:

irb(main):025:0> ->(x){x+3}.call 3
=> 6

So in ruby, block is not a block, but lambda is a block? Is this true? I mean, are there any differences between ruby lambda and smalltalk block? If this is true, then what is ruby block?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about block