Created
December 3, 2012 07:34
-
-
Save zhangyuan/4193410 to your computer and use it in GitHub Desktop.
use define_method to define class method
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
# 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