It’s good to follow Ruby convetions while writing Ruby programs. In this short tutorial I will a cover a few rules about naming variables, methods, classes and modules in Ruby.
Golabal variables in Ruby start with a dollar sign: $
$i_am_a_global_variable
Class variables are prefixed with two “at” signs: @@
@@i_am_a_class_variable
Instance variable starts with an “at” sign: @
@i_am_an_instance_variable
Local variables are in lowercase letters.
i_am_a_local_variable
Constants start with an uppercase letter.
PI
FeetPerMile
Class names begin with an uppercase letter.
class String
...
end
class ReadOnlyAssociation
...
end
Module names start with an uppercase letter like class names.
module Kernel
...
end
module ActiveRecord
...
end
In Ruby, method names and parameters should start with smallcase letter. If method name or parameters has includes than one words, you should separate them using underscores.
def my_method(param1, param2)
...
end