Ruby: @, @@, !, ?, #, and {}

January 14, 2008 § Leave a comment

This is post is intended to be a quick reference page for basic ruby consumption.

What is @

It is a sigil for instance variable. That means, the variable scope is within an instance of a class.

What is @@

It is a sigil for class variable. When defined in a class, duh,  the value is shared by all of its instances.

What is !

Ruby allows its function namespace to have exclamation point(!). When a function is declared with (!) sign, it means that the function will overwrite the caller’s value. For example:

test = “awesome”


puts test # test value is: emosewa

What is ?

Just like exclamation point, question mark is allowed in Ruby’s function namespace. When a function is ended with (?), the function is expected to return boolean value.

What is #

It is a sigil to mark the beginning of comment.

What is {}

It could means:

  1. a Hash. When assigned to a variable.
  2. beginning & end of a block (anonymous function).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

What’s this?

You are currently reading Ruby: @, @@, !, ?, #, and {} at RAPD.


%d bloggers like this: