Skip to content

Instantly share code, notes, and snippets.

@ys
Created June 13, 2013 08:15
Show Gist options
  • Save ys/5772055 to your computer and use it in GitHub Desktop.
Save ys/5772055 to your computer and use it in GitHub Desktop.
module Env
class EnvKeyError < StandardError; end
def self.method_missing(method_name, *arguments, &block)
env_value(method_name) { raise EnvKeyError, method_name }
end
def self.respond_to?(method_name, include_private = false)
env_value(method_name)
true
rescue StandardError
false
end
def self.method_to_key(method_name)
method_name.to_s.upcase
end
def self.env_value(method_name, &block)
block ||= -> { false }
ENV.fetch(method_to_key(method_name), &block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment