Created
October 8, 2012 02:24
-
-
Save fabiokung/3850407 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
class Stuff | |
def self.conf(*names) | |
names.each do |name| | |
define_singleton_method(name) do | |
@confs ||= {} | |
@confs[name] | |
end | |
define_singleton_method("#{name}=") do |value| | |
@confs ||= {} | |
@confs[name] = value | |
end | |
end | |
end | |
conf :aws_access_key, :aws_secret_key | |
end |
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
module WithConf | |
module ClassMethods | |
def conf(*names) | |
names.each do |name| | |
define_singleton_method(name) do | |
self.confs[name] | |
end | |
define_singleton_method("#{name}=") do |value| | |
self.confs[name] = value | |
end | |
end | |
end | |
def confs | |
@confs ||= {} | |
end | |
end | |
def self.included(klass) | |
klass.extend(ClassMethods) | |
end | |
end | |
class Stuff | |
include WithConf | |
conf :aws_access_key, :aws_secret_key | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment