Created
August 29, 2012 06:44
-
-
Save phiggins/3507564 to your computer and use it in GitHub Desktop.
Class configuration using OpenStruct
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
require 'ostruct' | |
module Awesome | |
def self.config | |
@config | |
end | |
def self.configure | |
yield(config) | |
end | |
class Configuration < OpenStruct ; end | |
@config = Configuration.new | |
end | |
Awesome.configure do |a| | |
a.magic_number = 3 | |
end | |
puts Awesome.config.magic_number | |
# => 3 | |
puts Awesome.config | |
# => #<Awesome::Configuration magic_number=3> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment