What are for you the pros and cons of using:
FooLib::Plugins FooLib::Plugins::Bar
vs.
FooLib::Plugin FooLib::Plugin::Bar
naming conventions? And what would you use or what are you using? What is more commonly used in the comunity?
Variable names in Ruby can be created from alphanumeric characters and the underscore _ character. A variable cannot begin with a number. This makes it easier for the interpreter to distinguish a literal number from a variable. Variable names cannot begin with a capital letter.
Namespace in Ruby allows multiple structures to be written using hierarchical manner. Thus, one can reuse the names within the single main namespace. The namespace in Ruby is defined by prefixing the keyword module in front of the namespace name. The name of namespaces and classes always start from a capital letter.
The method definitions look similar, too: Module methods are defined just like class methods. As with class methods, you call a module method by preceding its name with the module's name and a period, and you reference a constant using the module name and two colons.
Use:
module FooLib end module FooLib::Plugins end class FooLib::Plugins::Plugin; end #the base for plugins class FooLib::Plugins::Bar < FooLib::Plugins::Plugin; end class FooLib::Plugins::Bar2 < FooLib::Plugins::Plugin; end
or in a different words:
module FooLib module Plugins class Plugin; end #the base for plugins class Bar < Plugin; end class Bar2 < Plugin; end end end
Also arrange the files like this:
- foo_lib/ - plugins/ - plugin.rb - bar.rb - bar2.rb
This is how Rails does it (so this is the Rails Way). I.e. look at the Associations namespace and the Associations::Association class from which all of the classes form the Associations namespace inherits (i.e. Associations::SingularAssociation).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With