Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Created March 21, 2010 19:46
Show Gist options
  • Save Vaguery/339516 to your computer and use it in GitHub Desktop.
Save Vaguery/339516 to your computer and use it in GitHub Desktop.
# Convert the provided const desc to a qualified constant name (as a string).
# A module, class, symbol, or string may be provided.
def to_constant_name(desc) #:nodoc:
name = case desc
when String then desc.starts_with?('::') ? desc[2..-1] : desc
when Symbol then desc.to_s
when Module
raise ArgumentError, "Anonymous modules have no name to be referenced by" if desc.name.blank?
desc.name
else raise TypeError, "Not a valid constant descriptor: #{desc.inspect}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment