Naming conventions in Ruby on rails

By: Brian Marick Emailed: 1609 times Printed: 2079 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

A Ruby name may contain letters, numbers, and the underscore character (not a hyphen). Names can’t begin with a number, nor may they include spaces. Case matters: my_ship is not the same name as my_Ship.

When a name begins with a capital letter, you’re telling Ruby that you expect it always to refer to the same object. Ruby will complain if you try to use the same name for a different object:

irb(main):007:0> MyShip = "a cutter"

=> "a cutter"

irb(main):008:0> MyShip = "a bark"

(irb):4: warning: already initialized constant MyShip

=> "a bark"

(Ruby complains but still obeys.)

When a multiword name begins with a lowercase letter, it’s conventional to separate the words with underscores, like my_fine_name. When one begins with a capital letter, the convention is to capitalize each word:

MyFineName. I don’t know the rationale behind the difference. As a special case, message names can end with a question mark or an exclamation point. When one ends in a question mark, it’s a signal that the message asks a true/false question of its receiver. An exclamation point is a signal to the reader that the message does something special and perhaps unexpected.


Ruby Home | All Ruby Tutorials | Latest Ruby Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Brian Marick
The Question Mark Operator in Ruby on rails
unless in Ruby on rails
if . . . elsif . . . else in Ruby on rails
Methods in Ruby on rails
Command-line Arguments in Ruby on rails
Naming conventions in Ruby on rails

More Tutorials in Ruby
Standard Library Packages in Ruby
Module Abbrev in Ruby
encoding and decoding in Ruby using Base64 Module
Benchmark module in Ruby
benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) {|report| ...} in Ruby
bm(label_width = 0, *labels) {|report| ...} in Ruby
bmbm(width = 0) {|job| ...} in Ruby
CGI class in Ruby
URL encode a string in Ruby
escapeElement() in Ruby
escapeHTML() in Ruby
new(type = "query") in Ruby
parse(query) in Ruby
pretty() in Ruby
Format a Time object as a String in Ruby

More Latest News
Most Viewed Articles (in Ruby )
Standard Library Packages in Ruby
Prompts, Command Lines, Prompts, and irb in Ruby on rails
Benchmark module in Ruby
Getting started with Ruby on rails
Naming conventions in Ruby on rails
Command-line Arguments in Ruby on rails
Methods in Ruby on rails
The Question Mark Operator in Ruby on rails
CGI class in Ruby
URL encode a string in Ruby
URL decode a string in Ruby
unescapeHTML() in Ruby
out() in Ruby
IMAP in Ruby
Defining tables and classes (using MySQL) in Ruby on Rails
Most Emailed Articles (in Ruby)
encoding and decoding in Ruby using Base64 Module
Defining tables and classes (using MySQL) in Ruby on Rails
header() in Ruby
Using Generator in Ruby
Benchmark module in Ruby
Security in dRuby
Sending emails using SMTP in Ruby
Naming conventions in Ruby on rails
Module Abbrev in Ruby
bm(label_width = 0, *labels) {|report| ...} in Ruby
CGI class in Ruby
URL encode a string in Ruby
out() in Ruby
Using Proxy to connect to URLs in Ruby
IMAP in Ruby