Created
April 26, 2019 12:04
-
-
Save bradpauly/845b70872df9008f9cec9172c0967b96 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
class Configuration | |
def method_missing(name) | |
self.class.instance_variable_get("@#{name}") | |
end | |
def self.set(name, value) | |
instance_variable_set("@#{name}", value) | |
end | |
def self.default(name, value) | |
instance_variable_set("@#{name}", value) | |
end | |
end | |
class Foo < Configuration | |
default :bar, "baz" | |
default :a, 9 | |
end | |
f = Foo.new | |
f.bar | |
f.a | |
Foo.set(:bar, 12) | |
f.bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment