I was looking at the Rubocop rule for module/class specification notations, and these two options exist:
# Style/ClassAndModuleChildren: EnforcedStyle: compact
module M::C
# Style/ClassAndModuleChildren: EnforcedStyle: nested
module M
class C
The following two files, when run, show that the two are not identical in behavior (see the end of each file for output results):
# nested.rb
# Style/ClassAndModuleChildren: EnforcedStyle: nested
module OuterModule
def foo; puts 'foo'; end
end
module OuterModule
module InnerModule
def hello
puts 'hello'
end
end
end
module OuterModule
class C
include InnerModule
end
end
# Does not produce any error when run
# compact.rb
# Style/ClassAndModuleChildren: EnforcedStyle: compact
module OuterModule
def foo; puts 'foo'; end
end
module OuterModule
module InnerModule
def hello
puts 'hello'
end
end
end
class OuterModule::C
include InnerModule
end
=begin
❯ ruby compact.rb
Traceback (most recent call last):
1: from compact.rb:15:in `<main>'
compact.rb:16:in `<class:C>': uninitialized constant OuterModule::C::InnerModule (NameError)
Did you mean? OuterModule::InnerModule
end
Why is this?