Last active
December 14, 2015 19:19
-
-
Save vinbarnes/5136179 to your computer and use it in GitHub Desktop.
I'd prefer the second way unless there's some weird Ruby reason why I shouldn't...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module My | |
module Job | |
class ReconcileAccounts | |
# ... | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module My; end | |
module My::Job; end | |
class My::Job::ReconcileAccounts | |
# ... | |
end |
But, you can do:
module My; module Job; end; end;
and define the class as you prefer in example 2.
I frequently see in gems where the module definitions are at the root lib/gemname.rb file, and all the classes within that module just defined as Gemname::ClassName
in their respective files without repeating the explicit module definitions.
Second one should be
module My; end
module My::Job; end
But I'd recommend
My = Module.new
My::Job = Module.new
Because fuck semicolons. note: you can't do it my way in multiple files. You have to that globally.
Ahh nice, I always forget about Module/Class.new. Go with that.
@aniero duh. Forgot to namespace my modules. Thanks for the catch.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Job
will be defined at the same level asMy
, soMy::Job
won't work...