Created
January 15, 2014 07:18
-
-
Save anaumov/8432161 to your computer and use it in GitHub Desktop.
sample ActiveSupport::Configurable
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 CarConfig | |
include ActiveSupport::Configurable | |
config_accessor :brand | |
end | |
class Car | |
attr_accessor :brand | |
def initialize | |
self.brand = self.class.config.brand | |
end | |
class << self | |
attr_reader :config | |
def configure | |
@config ||= CarConfig.new | |
yield @config if block_given? | |
end | |
end | |
end | |
Car.configure do |config| | |
config.brand = 'Volvo' | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment