From: Robert Klemme Date: 2012-02-08T20:58:52+09:00 Subject: Re: Using _ like in Scala? On Wed, Feb 8, 2012 at 3:43 AM, Josh Cheek wrote: > On Tue, Feb 7, 2012 at 9:15 AM, Robert Klemme wrote: > >> > Although what I'd really like would be a syntax for naming inline blocks, >> > then my editor could fold the block body inside the name, something like >> > %w[apple banana orange].each display >> > >> > And it would expand to something like >> > %w[apple banana orange].each { |display -> fruit| puts fruit } >> >> How would the above be derived from the line further up? >> > The name would have no impact on the language, it is still just a block > which takes one argument. It exists to help the developer (and be used by > the editor). Hmm... Maybe I wasn't clear enough. I was trying to ask how any automated mechanism could read %w[apple banana orange].each display and know it must make %w[apple banana orange].each { |display -> fruit| puts fruit } from it. I am asking specifically since "puts" is nowhere mentioned in the line above. So even if the syntax would be allowed there would have to be some ruling which leads to an interpretation equivalent to the second line. > Often examples become more complicated, I often feel that the contents of a > block are at a different level of abstraction from the containing code (the > block is a "how I do it" but I'd like to just look at a "what I am doing", > which is where the name has relevance). But examples posted here should be at least realistic so we are not discussing the wrong use case. In case of printing an Enumerable "puts enum" is certainly the best option. :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/