Skip to content

Instantly share code, notes, and snippets.

@the-teacher
Created August 23, 2013 13:08
Show Gist options
  • Save the-teacher/6319174 to your computer and use it in GitHub Desktop.
Save the-teacher/6319174 to your computer and use it in GitHub Desktop.
ruby check for class exists
# 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