4 ms·
They are indeed all Proc objects: Proc.new {}.class => Proc lambda {}.class => Proc proc {}.class => Proc def block_class(&block) b
by carbon8 17y ago
They are indeed all Proc objects:
Proc.new {}.class
=> Proc
lambda {}.class
=> Proc
proc {}.class
=> Proc
def block_class(&block) block.class end
block_class {}
=> Proc
That write-up does have some great info in it, though.
Edit: there's an interesting comment on wycats' post that suggests the &block creates a Proc, and that blocks themselves are neither objects nor callable, ie, they can only be used directly with yield. That makes sense.
Even in that case, the original point still stands; we're still only dealing with Methods and Procs.
- arohner 17y agoMy link empirically demonstrates that all 7(!) constructs behave differently, regardless of what foo.class says. I personally have been burned by the differences between them, so I'll continue to support people differentiating between them, even if the interpret lies.
- carbon8 17y ago"My link empirically demonstrates that all 7(!) constructs behave differently" It explicitly doesn't. Read it again. Immediately after listing his 7 constructs he points out that a number of them are actually the same thing, and in the summary he clearly explains that there are only 4 different behaviors. His 7 constructs (which include methods and bare blocks) are actually only 3 or, arguably, 3.5/4 (his numbers in parens): blocks, which aren't callable without being wrapped in a Proc in CRuby (1, 2) Procs (two types: Proc.new/&block and lambda) (3, 4, 5, 6) methods (7) There two types of Procs, plain procs and lambda, with lambda's differences being how it checks arguments and its return behavior, as I noted yesterday in another comment in this discussion (http://news.ycombinator.com/item?id=1141030 http://news.ycombinator.com/item?id=1141030). So, again, the original comment, "four goddamn callable types [Methods, Procs, Blocks, Lambdas]," neglects the fact that #call on the last three is actually just Proc#call.