From: Robert Klemme Date: 2012-02-09T00:57:37+09:00 Subject: Re: Using _ like in Scala? On Wed, Feb 8, 2012 at 4:30 PM, Josh Cheek wrote: > On Wed, Feb 8, 2012 at 5:58 AM, Robert Klemme wrote: > >> On Wed, Feb 8, 2012 at 3:43 AM, Josh Cheek wrote: >> > On Tue, Feb 7, 2012 at 9:15 AM, Robert Klemme < >> shortcutter@googlemail.com>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. >> >> > Not sure about other editors, but TextMate knows what context it is in if > you write something like `[].each { |e| }` put your cursor before the e and > press C-P, it tells you variable.other.block.ruby. So it knows when it is > in block paramaters, it would just need to then understand that within this > context, if it sees something like `|name -> var|` that "name" is the name > of this block, and then just allow for block folding. It actually already > does all this > https://s3.amazonaws.com/josh.cheek/images/scratch/block_folding.png but > instead of showing '...' it could show 'name ...' So you are talking about an editor feature and not a language feature? I am starting to get an idea of where I misunderstood you... :-) > In this example, for instance > https://github.com/JoshCheek/deject/blob/5bc94b05cfca045afebcb447170d9f549b9e4006/lib/deject/object_oriented.rb#L39-43 > > It would be nice if I could define the block like this `|override_body -> > value=nil, &initializer|` > > Which would then get folded up like this (with visual distinction clues > provided by the highlighter) > > def define_override >  ivar, meth = self.ivar, self.meth >  klass.send :define_method, "with_#{meth}" override_body... > end > > That method is pretty easy to understand, but when you expand it, the code > of the body is inline with the code that sets up the definition, causing it > to take much more effort to understand (you parse/interpret it to determine > what is and is not relevant to you). Again, an editor feature? Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/