[ruby-core:121497] [Ruby Feature#21209] Endless classes and modules
From:
"Dan0042 (Daniel DeLorme) via ruby-core" <ruby-core@...>
Date:
2025-04-01 15:36:11 UTC
List:
ruby-core #121497
Issue #21209 has been reported by Dan0042 (Daniel DeLorme).
----------------------------------------
Feature #21209: Endless classes and modules
https://bugs.ruby-lang.org/issues/21209
* Author: Dan0042 (Daniel DeLorme)
* Status: Open
----------------------------------------
Endless methods have proven popular enough that we should bring the same endlessness to module/class definitions.
For a long time we've had this ugly pattern of class definitions with an extreme 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
def firstmethod
"man, I'm just the first method and already indented 14 spaces deep!"
end
end #what
end #a
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!
--
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.ruby-lang.org/