Created
March 9, 2015 15:38
-
-
Save Shinpeim/e8e93e0382388a3e29a2 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
module Nyan | |
class ConfigStore | |
class << self | |
attr_writer :setting_a, :setting_b, :setting_c | |
def setting_a | |
@setting_a || "default a" | |
end | |
def setting_b | |
@setting_b || "default b" | |
end | |
def setting_c | |
@setting_c || "default c" | |
end | |
end | |
end | |
class Processor | |
def run | |
a = ConfigStore.setting_a | |
b = ConfigStore.setting_b | |
c = ConfigStore.setting_c | |
p "a: #{a}, b: #{b}, c: #{c}" | |
end | |
end | |
def self.configure | |
yield ConfigStore | |
end | |
end | |
# configure process global options | |
Nyan.configure do |c| | |
c.setting_a = "aa" | |
c.setting_c = "cc" | |
end | |
a = Nyan::Processor.new | |
a.run # => "a: aa, b: default b, c: cc" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment