Created
March 9, 2011 06:45
-
-
Save hryk/861791 to your computer and use it in GitHub Desktop.
constantize_with_context
This file contains hidden or 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
| class String | |
| def constantize_with_context(context=nil, args={:raise => true}) | |
| unless context.nil? | |
| begin | |
| const = context.const_get self.to_sym | |
| rescue NameError => e | |
| if args[:raise] | |
| raise e | |
| else | |
| return constantize_without_context | |
| end | |
| else | |
| return const | |
| end | |
| else | |
| constantize_without_context | |
| end | |
| end | |
| alias_method_chain :constantize, :context | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment