Project

General

Profile

Actions

Feature #21209

open

Endless classes and modules

Added by Dan0042 (Daniel DeLorme) 1 day ago. Updated about 5 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:121497]

Description

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:

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:

module Arel
module Visitors
class UnsupportedVisitError
module ClassMethod
module AmIDeepEnough
module NoNotDeepEnough
class LetsGoDeepter

def firstmethod
  "now that's better!"
end

Brilliant!


Related issues 1 (1 open0 closed)

Related to Ruby - Feature #21155: File scoped namespace declarations as in C#OpenActions
Actions #1

Updated by mame (Yusuke Endoh) about 5 hours ago

  • Related to Feature #21155: File scoped namespace declarations as in C# added

Updated by mame (Yusuke Endoh) about 5 hours ago

A similar issue was raised in #21155. We discussed that issue at the last dev meeting, and several endless class definition syntax was proposed.

module = Foo

in module Foo

for module Foo

However, @matz (Yukihiro Matsumoto) didn't like any of them. Also, he said that this issue was inevitable in object-oriented programming, and that he would close #21155 (which doesn't seem to be closed yet).

So perhaps this proposal is also hopeless. (Personally, I would like to solve this problem, though.)

Actions

Also available in: Atom PDF

Like0
Like0Like0