Skip to content

Instantly share code, notes, and snippets.

@phiggins
Created August 29, 2012 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phiggins/3507548 to your computer and use it in GitHub Desktop.
Save phiggins/3507548 to your computer and use it in GitHub Desktop.
Class configuration using method_missing
module Awesome
@config = {}
def self.configure
yield(self)
end
def self.method_missing method, *args, &block
if method.to_s[-1] == '='
@config[method[0..-2].to_sym] = args.first
else
@config[method]
end
end
end
Awesome.configure do |a|
a.magic_number = 3
end
puts Awesome.magic_number
# => 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment