Created
March 21, 2010 19:46
-
-
Save Vaguery/339516 to your computer and use it in GitHub Desktop.
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
# 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