Created
August 23, 2013 13:08
-
-
Save the-teacher/6319174 to your computer and use it in GitHub Desktop.
ruby check for class exists
This file contains 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
# the_class_exists? :User => true | false | |
# the_class_exists? :Role => true | false | |
def the_class_exists?(class_name) | |
klass = Module.const_get(class_name) | |
return klass.is_a?(Class) | |
rescue NameError | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment