Skip to content

Instantly share code, notes, and snippets.

@zhangyuan
Created December 3, 2012 07:34
Show Gist options
  • Save zhangyuan/4193410 to your computer and use it in GitHub Desktop.
Save zhangyuan/4193410 to your computer and use it in GitHub Desktop.
use define_method to define class method
# via: http://stackoverflow.com/questions/752717/how-do-i-use-define-method-to-create-class-methods
class Environment
def self.current
ENV['APP_ENV'] ||= 'development'
end
%w(development product test).each do |environment|
(class << self; self; end).instance_eval do
define_method "#{environment}?" do
self.current.to_s == environment.to_s
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment