Ruby: Step by Step Study
Keywords and Identifiers
The keywords (or reserved words) in Ruby typically cannot be used for other purposes. These are as follows:
Variables and other identifiers normally start with an alphabetic letter or a special modifier. The basic rules are as follows:
-
Local variables (and pseudo-variables such as self and nil) begin with a lowercase letter.
-
Instance variables (within an object) begin with an "at" sign (@).
-
Class variables (within a class) begin with two "at" signs (@@).
-
Constants begin with capital letters.
For purposes of forming identifiers, the underscore (_) may be used as a lowercase letter. Special variables starting with a dollar sign (such as $1 and $/) are not dealt with here.
The following list provides some examples:
-
Local variables: alpha, _ident, some_var
-
Pseudo-variables: self, nil, __FILE__
-
Constants: K6chip, Length, LENGTH
-
Instance variables: @foobar, @thx1138, @NOT_CONST
-
Class variable: @@phydeaux, @@my_var, @@NOT_CONST
芳兒寶貝.我愛你

posted on 2007-12-11 15:15 wǒ愛伱--咾婆 閱讀(262) 評論(0) 編輯 收藏 所屬分類: Ruby Study