Symbol

From RubySpec

Jump to: navigation, search

Symbol objects denote names inside the Ruby interpreter. "They are generated automatically using the :name literal syntax" If Foo is a class in one context, a method in another context, and a constant in the third, the symbol :Foo is the same object in all the contexts.(Programming Ruby, 1st edition).

For example,

 module Math #Remember, Math is an existing module
   $f2 = :sin
 end
 def sin()
 end
 $f3 = :sin
 puts $f1.object_id  
 puts $f2.object_id  
 puts $f3.object_id
Personal tools