module Stove::Mixin::Optionable::ClassMethods
Public Instance Methods
option(name, initial = UNSET_VALUE)
click to toggle source
This is a magical method. It does three things:
-
Defines a class method getter and setter for the given option
-
Defines an instance method that delegates to the class method
-
(Optionally) sets the initial value
@param [String, Symbol] name
the name of the option
@param [Object] initial
the initial value to set (optional)
# File lib/stove/mixins/optionable.rb, line 24 def option(name, initial = UNSET_VALUE) define_singleton_method(name) do |value = UNSET_VALUE| if value == UNSET_VALUE instance_variable_get("@#{name}") else instance_variable_set("@#{name}", value) end end define_method(name) { self.class.send(name) } unless initial == UNSET_VALUE send(name, initial) end end