Skip to content

Instantly share code, notes, and snippets.

@vinbarnes
Last active December 14, 2015 19:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinbarnes/5136179 to your computer and use it in GitHub Desktop.
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...
module My
module Job
class ReconcileAccounts
# ...
end
end
end
module My; end
module My::Job; end
class My::Job::ReconcileAccounts
# ...
end
@zerowidth
Copy link

Job will be defined at the same level as My, so My::Job won't work...

@zerowidth
Copy link

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.

@nuclearsandwich
Copy link

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.

@zerowidth
Copy link

Ahh nice, I always forget about Module/Class.new. Go with that.

@vinbarnes
Copy link
Author

@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