Project

to-class

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Get a class from a symbol or string of its name in one fell swoop.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

To Class

This gem adds a to_class method to ActiveSupport::Inflector, Symbol, and String that combines the functionality of ActiveSupport’s camelize and constantize methods—it will convert the object in question to Camel case and then try to find a declared constant with the corresponding name. This allows you to easily get a class from its name with one simple method invocation.

Full documentation is at RubyDoc.info.

Examples

:user.to_class       #=> User
'user'.to_class      #=> User
:blog_post.to_class  #=> BlogPost
'blog_post'.to_class #=> BlogPost

Colophon

See also

If you like this gem, you may also want to check out Easier Instance Variable Access.

Tested with

  • ActiveSupport 3.0.5 — 20 May 2011

Contributing

To send patches, please fork on GitHub and submit a pull request.

Credits

© 2011 Cody Robbins. See LICENSE for details.