Issue #5054 has been updated by Ralph Corderoy.


With reference to e+nd or en+d;  I haven't had to count characters since
Hollerith string constants in Fortran;  11HHELLO WORLD  ;-).  My
suggestion is to introduce end{if,while,def,...} as keywords;  they act
as one or more "end"s up to the nearest enclosing if/while/...  Using
the initial example above:

    module MyModule
      class MyClass
        def my_method
          10.times do
            if rand < 0.5 
              p :small
    endmodule

Obviously, the indentation of the end* would match the intended opening
keyword but parsing or readability doesn't depend on it.

    def my_method 10.times do if rand < 0.5 p :small enddef

Sure, sometimes you'd still need to double them up, "endif endif",
because each only goes to the nearest "if" on the parse stack, but that
would be unusual and still an overall win over the many "end"s needed
instead, each on a line.

Disclosure, I'm not a Ruby programmer, preferring Python, but I hope
that doesn't mean the suggestion is dismissed out of hand.  :-)
----------------------------------------
Feature #5054: Compress a sequence of ends
http://redmine.ruby-lang.org/issues/5054

Author: ANDO Yasushi ANDO
Status: Open
Priority: Normal
Assignee: 
Category: 
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