From: Josh Cheek Date: 2012-02-08T11:43:14+09:00 Subject: Re: Using _ like in Scala? --f46d0442815840f19304b86adb8d Content-Type: text/plain; charset=ISO-8859-1 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). > > But never found anything I was very happy with. > > Actually in this case "puts fruits" would be the best solution. ;-) > Did anybody suggest it before? > > In this case, yes :P 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). On Tue, Feb 7, 2012 at 6:30 PM, Kevin wrote: > > What -- like this? > > > > $ irb > > >> fruits = ['apple', 'orange'] > > => ["apple", "orange"] > > >> puts fruits > > apple > > orange > > => nil > > Yes. Does this only work in the REPL? I've never tried that kind of > order in real code. > > No, this works everywhere. It is just how the puts method deals with arrays http://rubydoc.info/stdlib/core/1.9.3/IO:puts --f46d0442815840f19304b86adb8d--