When you want to use module A as a namespace to work within for the entire file, you can just put:
include A
and whatever follows will be within A. Is there a way to do a similar thing with class B?
Putting:
class B
at the beginning of the file, and after all contents of the file, ending the file all the way down with
end
does not look elegant, and is a cause of mistake. I am looking for a way that does not require a closing command like end.
Edit My description above about include A seemed to be wrong. Even after doing so, the environment is still the main object. What I want is to make it possible so that if I just do
def foo; ... end
without any explicit nesting, then that will be defined as a method to A or B for the respective cases.
To me best knowledge, there is no such directive.
Though if your files are going to “executed” by another script what you can do is this:
File
file.rbcontainsFile
main.rbcontainsIf you like to make this more transparent, you might even provide your own implementation of require which hides all this magic.