Skip to content

Instantly share code, notes, and snippets.

@bradpauly
Created April 26, 2019 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradpauly/845b70872df9008f9cec9172c0967b96 to your computer and use it in GitHub Desktop.
Save bradpauly/845b70872df9008f9cec9172c0967b96 to your computer and use it in GitHub Desktop.
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