-
-
Save kyanny/26b5cb9b3e06b982be54 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
require 'delegate' | |
require 'ostruct' | |
class MyProxyClass < SimpleDelegator | |
def initialize(env) | |
super(OpenStruct.new(env)) | |
end | |
def method_missing(method, *args) | |
super | |
rescue NoMethodError | |
super(method.upcase, *args) | |
rescue NoMethodError | |
nil | |
end | |
end | |
env_proxy = MyProxyClass.new(ENV) | |
p env_proxy.USER | |
p env_proxy.user | |
p env_proxy.unknown_environment_variable |
Author
kyanny
commented
Mar 7, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment