Created
April 26, 2014 16:18
-
-
Save cheeyeo/11324200 to your computer and use it in GitHub Desktop.
Object.const get
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def string_to_constant(constant_name) | |
constant_name.split("::").inject(Object) { |s,e| s.const_get(e) } | |
end | |
class Article; end | |
string_to_constant("Article") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment