Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created March 9, 2015 15:38
Show Gist options
  • Save Shinpeim/e8e93e0382388a3e29a2 to your computer and use it in GitHub Desktop.
Save Shinpeim/e8e93e0382388a3e29a2 to your computer and use it in GitHub Desktop.
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