From: Rick DeNatale Date: 2008-05-27T23:49:42+09:00 Subject: Re: OOP in Ruby? On Tue, May 27, 2008 at 10:02 AM, Huw Collingbourne wrote: > Robert Dober wrote: >> I agree upto here, but... >>>- that is, just writing a block in code does not make it an >>> instance of a Block (or Proc) class. >> I however believe it does, if you write a block in Ruby it is always >> passed on to a method > > Therein lies the difference. If you write a block in Smalltalk it has an > independent existence. In theory, but not necessarily in practice. In reality most Smalltalk implementations will not reify the "block" arguments to methods like ifTrue:, ifFalse:, ifTrue:ifFalse, and ifFalse:ifTrue: instead they cheat and compile test and branch bytecodes, and throw an exception if the 'receiver' isn't a boolean. http://talklikeaduck.denhaven2.com/articles/2008/05/21/what-would-you-miss-if-you-had-to-stop-using-ruby-and-go-back-to-smalltalk The real difference, I think, is that in Smalltalk you can have multiple arguments in a message which are coded as block literals, where as in Ruby block literals can only be used as the final argument to a method, and that that argument doesn't need to be explicitly named if is invoked by the method using yield, or if it's ignored by the method. There's quite a discussion going on right now on ruby-core about the esthetics of the new '->' "fallen over lambda" operator in 1.9 and whether it would be better to allow a call like: a.m({|b|...}, {|| ...}) where the |..| distinguish a block from a hash. I don't know the ultimate fate of the proposal, but it DOES make ruby syntax look a bit more like Smalltalk. It makes me wonder what Ruby would look like had Matz chosen square brackets rather than braces to delimit block literals. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/