[RoR],[C.L.R] How I convert an AR-Class-name to a symbol?

People,

I’m looking for a method to convert an AR-Class-name to a symbol.

Something like this:

AppServerType.class_name_to_symbol
=> :app_server_type

Also I’m looking for this:

:app_server_type.symbol_to_class_name
=> “AppServerType”

I’m sure this code sits in rails somewhere.

I can see evidence of its use all over the place but
I’m not tuned-in enough to find it.

I tried to find some clues here:

http://api.rubyonrails.org

But, I see too much info there.

-Peter

Peter,

Check out the Inflector module.

Wes

MyModel.name.underscore.to_sym
=> :my_model

:my_model.to_s.camelize.constantize
=> MyModel

On Feb 20, 8:56 pm, Wes G. [email protected]

I tried to find some clues here:

http://api.rubyonrails.org

This is a good place to look too:
http://www.ruby-doc.org/core/

Take a look at the to_sym method for the String class and the to_s
method for the Symbol class.

“hello”.to_sym => :hello
:hello.to_s => “hello”

Aaron

Hi there…

“AppServer”.tableize

#=> “app_servers”

close enough… ?

jason.

Thanks!

Now I’m curious about how to change:
“AppServer”
to
“app_server”

-Peter