Project

General

Profile

Actions

Feature #9070

open

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

Added by alexeymuranov (Alexey Muranov) over 10 years ago. Updated over 10 years ago.

Status:
Open
Target version:
-
[ruby-core:58120]

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
attr_reader :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
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

=end

Updated by matz (Yukihiro Matsumoto) over 10 years ago

  • Assignee set to matz (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.

Updated by sikachu (Prem Sichanugrist) over 10 years 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.

Updated by alexeymuranov (Alexey Muranov) over 10 years 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.

Updated by david_macmahon (David MacMahon) over 10 years 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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0