From: "Martin Dürst" Date: 2011-07-21T13:26:41+09:00 Subject: [ruby-core:38296] [Ruby 1.9 - Feature #5054] Compress a sequence of ends Issue #5054 has been updated by Martin D��rst. Kurtis Rainbolt-Greene wrote: > The `endwhile` and `endif` or `fi` solutions aren't *solutions* because they can't be used for block arguments for methods: > > method do > method2 do > method3 do > end > end > end > > Whatever solution comes, it needs to also work with block style DSLs, as they are our greatest resource. What about enddo? That would work in the example above. We would have to think how to integrate {} blocks. On a different note, when programming Ruby, I occasionally hit interpreter messages that cryptically say that there's an end too much or too few. These always feel difficult to debug. The best strategy that I have come up with is to arbitrarily insert/remove additional ends somewhere, and see what happens, and zoom in on the problem location with something close to binary search. While reading this discussion, it occurred to me that endif/endwhile/enddo/... might make such kind of debugging easier. ---------------------------------------- Feature #5054: Compress a sequence of ends http://redmine.ruby-lang.org/issues/5054 Author: Yasushi ANDO Status: Assigned Priority: Normal Assignee: Yasushi ANDO Category: Joke Target version: Though as matz said at rubykaigi2011 ruby is a quite good language, many people hate a long sequence of `end' like this: module MyModule class MyClass def my_method 10.times do if rand < 0.5 p :small end end end end end So, I'd like to propose introducing a special keyword, en(n+)d. Using this keyword, we can rewrite the above example like this: module MyModule class MyClass def my_method 10.times do if rand < 0.5 p :small ennnnnd I know matz's already rejected a python-style block. He wrote: > it works badly with > * tab/space mixture > * templates, e.g. eRuby > * expression with code chunk, e.g lambdas and blocks http://www.ruby-forum.com/topic/108457 These bad things won't occur by introducing en(n+)d. Some implementations already exists. JRuby - https://gist.github.com/1088363 CRuby - http://www.atdot.net/sp/raw/kn9iol - http://d.hatena.ne.jp/ku-ma-me/20110718/p1 Thanks for your consideration. -- http://redmine.ruby-lang.org