Skip to content

Instantly share code, notes, and snippets.

@fabiokung
Created October 8, 2012 02:24
Show Gist options
  • Save fabiokung/3850407 to your computer and use it in GitHub Desktop.
Save fabiokung/3850407 to your computer and use it in GitHub Desktop.
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
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