Feature #9070

Introduce `---` as synonym of `end` keyword

Added by Alexey Muranov 6 months ago. Updated 6 months ago.

[ruby-core:58120]
Status:Open
Priority:Normal
Assignee:Yukihiro Matsumoto
Category:-
Target version:-

Description

=begin
This is just an idea: introduce "(({---}))" as synonym of "(({end}))" keyword.

It is a bit easier to type and to read, and makes whitespace insensitive language look as if it follows off-side rule. Compare:

class Person
attrreader :name, :age
def initialize(name, age)
@name, @age = name, age
---
def <=>(person) # the comparison operator for sorting
age <=> person.age
---
def to
s
"#{name} (#{age})"
---


class Person
attrreader :name, :age
def initialize(name, age)
@name, @age = name, age
end
def <=>(person) # the comparison operator for sorting
age <=> person.age
end
def to
s
"#{name} (#{age})"
end
end

=end

History

#1 Updated by Yukihiro Matsumoto 6 months ago

  • Assignee set to Yukihiro Matsumoto

Hmm, interesting idea. But it looks bit ugly, isn't it?

FYI, I have once experimented ';;' as replacement of 'end' (I even modified ruby-mode.el as well).
But it turned out to be confusing, and I gave up.

I am not sure your '---' idea will work. Seems better than ';;' at least.

Matz.

#2 Updated by Prem Sichanugrist 6 months ago

It does look ugly. I don't think that really makes the code better.

Also, I think if you leave a space after each method, then end really works fine here.

#3 Updated by Alexey Muranov 6 months ago

matz (Yukihiro Matsumoto) wrote:

Hmm, interesting idea. But it looks bit ugly, isn't it?

FYI, I have once experimented ';;' as replacement of 'end' (I even modified ruby-mode.el as well).
But it turned out to be confusing, and I gave up.

I am not sure your '---' idea will work. Seems better than ';;' at least.

So, maybe the Feedback status for now? I imagine this is a matter of personal taste, i proposed because i think i would have liked my code to look like that. This looks to me like the best approximation to the indentation based syntax without being indentation based.

#4 Updated by David MacMahon 6 months ago

On Nov 1, 2013, at 10:44 AM, alexeymuranov (Alexey Muranov) wrote:

This looks to me like the best approximation to the indentation based syntax without being indentation based.

One easy way to get that appearance right now would be to append ";end" to the end of the preceding line:

class Person
attr_reader :name, :age
def initialize(name, age)
@name, @age = name, age ;end

def <=>(person) # the comparison operator for sorting
  age <=> person.age; end

def to_s
  "#{name} (#{age})" ;end ;end

Of course, when adding a new method at the end of class Person you need to make sure to put it in between the two ";end" statements.

Disclaimer: I am not advocating this solution; I am just pointing out that it could be done this way. I personally like having outdented "end" statements on separate lines, but this is obviously a subjective preference. Giving lexical significant to the amount of whitespace at the beginning of line really bothers me and is one of the reasons I prefer Ruby to Python! :-)

Dave

Also available in: Atom PDF