Skip to content

Instantly share code, notes, and snippets.

@hryk
Created March 9, 2011 06:45
Show Gist options
  • Select an option

  • Save hryk/861791 to your computer and use it in GitHub Desktop.

Select an option

Save hryk/861791 to your computer and use it in GitHub Desktop.
constantize_with_context
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