tags:

views:

70

answers:

2

What does the to_sym method do? What is it used for?

+4  A: 

to_sym converts a string to a symbol. For example, "a".to_sym becomes :a.

It's not specific to Rails; vanilla Ruby has it as well.

EDIT: It looks like in some versions of Ruby, a symbol could be converted to and from a Fixnum as well. But irb from Ruby 1.9.2-p0 from ruby-lang.org, doesn't allow that unless you add your own to_sym method to Fixnum. I dunno whether Rails does that, but it doesn't seem very useful.

cHao
+2  A: 

1st link at http://google.com/search?q=ruby+to_sym

Nakilon