Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created October 30, 2012 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/3981747 to your computer and use it in GitHub Desktop.
Save havenwood/3981747 to your computer and use it in GitHub Desktop.
Check if a symbol has been defined?
class << Symbol
def exists? sym
!all_symbols.grep(/^#{sym}$/).empty?
end
end
Symbol.exists? 'to_s'
#=> true
Symbol.exists? 'omgwtfbbq'
#=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment