I need to create a class that represent "SVN" inside a module called "SCM". But I don't know what is the convention when dealing with acronyms in Ruby, and could not find anything relevant in Google, except "Camel case is preferred".
Should I call it SCM::SVN
or Scm::Svn
? Is there a convention for this?
Classes and modules use MixedCase and have no underscores, each word starts with a uppercase letter. Database Table - e.g. invoice_items, orders Table names have all lowercase letters and underscores between words, also all table names need to be plural.
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.
What is an example of a good naming convention? Good naming examples include: [Project number] - Data Use Agreement - [Title of research project] Approval - Change to employee travel policy - February 2014.
Methods should be verbs in lowerCamelCase or a multi-word name that begins with a verb in lowercase; that is, with the first letter lowercase and the first letters of subsequent words in uppercase. Local variables, instance variables, and class variables are also written in lowerCamelCase .
Add the following to config/initializers/inflections.rb
.
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'SVN'
end
Now running $ rails g model SVN…
will create a class named SVN
in a file named svn.rb
and an associated table svns
.
SCM::SVN
looks best to me. Rails is full of classes like ERB, ORM and OMFGIMATEAPOT. And that's not to mention things like JSONSerializer. Ruby's source has a bunch of acronyms, too. The most obvious example to me is YAML
. The standard as I've seen it is to upcase letters for CamelCase but generally not to downcase them (although Rails has opinions on model names).
If you have grep and the source code you can see plenty of examples with something like
grep -r 'class [A-Z]\{3,\}' <path/to/source>
# or, if you only want acronyms and nothing like YAMLColumn:
grep -rw 'class [A-Z]\{3,\}' <path/to/source>
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