Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Ruby Programming
Previous Page Home Next Page

Names

Ruby names are used to refer to constants, variables, methods, classes, and modules. The first character of a name helps Ruby to distinguish its intended use. Certain names, listed in Table 18.3 on page 210, are reserved words and should not be used as variable, method, class, or module names.

Reserved words

__FILE__ and def end in or self unless
__LINE__ begin defined? ensure module redo super until
BEGIN break do false next rescue then when
END case else for nil retry true while
alias class elsif if not return undef yield

In these descriptions, lowercase letter means the characters ``a'' though ``z'', as well as ``_'', the underscore. Uppercase letter means ``A'' though ``Z,'' and digit means ``0'' through ``9.'' Name characters means any combination of upper- and lowercase letters and digits.

A local variable name consists of a lowercase letter followed by name characters.

fred  anObject  _x  three_two_one

An instance variable name starts with an ``at'' sign (``@'') followed by an upper- or lowercase letter, optionally followed by name characters.

@name  @_  @Size

A class variable name starts with two ``at'' signs (``@@'') followed by an upper- or lowercase letter, optionally followed by name characters.

@@name  @@_  @@Size

A constant name starts with an uppercase letter followed by name characters. Class names and module names are constants, and follow the constant naming conventions. By convention, constant variables are normally spelled using uppercase letters and underscores throughout.

module Math
  PI = 3.1415926
end
class BigBlob

Global variables, and some special system variables, start with a dollar sign (``$'') followed by name characters. In addition, there is a set of two-character variable names in which the second character is a punctuation character. These predefined variables are listed starting on page 213. Finally, a global variable name can be formed using ``$-'' followed by any single character.

$params  $PROGRAM  $!  $_  $-a  $-.

Method names are described in the section beginning on page 225.
Ruby Programming
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire