From: "Adam P. Jenkins" Date: 2005-06-30T02:20:46+09:00 Subject: Re: yield does not take a block Eric Mahurin wrote: > --- "Adam P. Jenkins" wrote: > >>Rather I have to wrap print >>in a block: >> >> myArray.each { |elem| print elem } >> >>Wouldn't it have been cool to just be able to write: >> >> myArray.each print > > > The reason you can't is because a method name by itself calls > the method instead of returning the method object. Ok, fair enough. I would still prefer just myArray.each :print or myArray.each &print than having to wrap it in a block. If you had > to put () to make the call and the method name by itself > returned the method object (I would have preferred that), you > could do this: > > myArray.each(&print) > > but, this should work fine right now: > > myArray.each(&method(:print)) Cool, I didn't know about that. Still, myArray.each &method(:print) myArray.each {|e| print e } Not much advantage really. Obviously you can do what you need to do in the current Ruby implementation, it's just annoying and inconsistent in the same way that it's annoying in Java that you need to box or unbox primitive types depending on the context. Even the Java 1.5 syntactic sugar for autoboxing doesn't completely hide the distinction. Coming from programming in functional languages, Ruby's distinction between blocks, closures, and methods seems similarly unnecessary at a language level, though like Java's primitive/Object distinction, it's probably a useful compromise for runtime efficiency. Adam