Ruby’s relatively complex identifier syntax carries quite a lot of semantic information. Ruby also borrows a diverse set of predefined globals from Perl.

Names can begin with a variety of characters (see below) and can contain letters (upper or lower case), digits, multibyte characters, and underscores.

IdentChar = IdentNonDigit | Digit

IdentNonDigit = UppercaseLetter | LowercaseLetter | MultibyteCharacter | _

GlobalVar = PredefinedGlobal | $IdentChar0 | $-[IdentChar] | $Digit2

PredefinedGlobal = $_ | $~ | $* | $$ | $? | $! | $@ | $/ | $\ | $; | $, | $. | $= | $: | $< | $> | $” | $& | $` | $’ | $+ | $Digit

ClassVar = @@ IdentNonDigit IdentChar0

Note: @@1 thru @@9 are invalid class variables, and that @@ by itself is not a valid class variable.

InstanceVar = @ IdentNonDigit IdentChar0

Note: @1 thru @9 are invalid instance variables, but ‘@’ appears to be a valid instance variable.
LocalName = ( LowercaseLetter | _ ) IdentChar0

ConstName = UppercaseLetter IdentChar0

FieldName = IdentChar1 [ ! | ? ]

Note: If an identifier begins with an identifier character and ends with ! or ?, it must not be followed immediately by = or ?.

FName = LocalName | ConstName | FieldName | Op | ReservedWord

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

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: