[ruby-core:121530] [Ruby Misc#21209] Endless classes and modules
From:
duerst via ruby-core <ruby-core@...>
Date:
2025-04-02 23:59:58 UTC
List:
ruby-core #121530
Issue #21209 has been updated by duerst (Martin D=FCrst).
Tracker changed from Feature to Misc
Status changed from Open to Closed
There's something special about proposals on April 1st, isn't there?
----------------------------------------
Misc #21209: Endless classes and modules
https://bugs.ruby-lang.org/issues/21209#change-112556
* Author: Dan0042 (Daniel DeLorme)
* Status: Closed
----------------------------------------
Endless methods have proven popular enough that we should bring the same en=
dlessness to module/class definitions.
For a long time we've had this ugly pattern of class definitions with an ex=
treme level of indentation.
I propose a simple new rule to fix this: if a 'class' or 'module' statement=
is at the beginning of a line, the matching 'end' becomes optional; EOF is=
enough.
instead of:
```ruby
module Arel
module Visitors
class UnsupportedVisitError
module ClassMethod
module AmIDeepEnough
module NoNotDeepEnough
class LetsGoDeepter
=20
def firstmethod
"man, I'm just the first method and already indented 14 spa=
ces deep!"
end
=20
end #what
end #a=20
end #chain
end #we
end #have
end #here
end #weee!!!
```
we can have the much more readable:
```ruby
module Arel
module Visitors
class UnsupportedVisitError
module ClassMethod
module AmIDeepEnough
module NoNotDeepEnough
class LetsGoDeepter
def firstmethod
"now that's better!"
end
```
Brilliant!
--=20
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.rub=
y-lang.org/