module CoreRefinements::Object::Options

Public Instance Methods

add_option(key = nil) click to toggle source

Add a trackable option to an object. Creates a method for the key name.

# File lib/core_refinements/Object/options.rb, line 6
def add_option(key = nil)
  @_added_options ||= []
  @_added_options.push(key.to_sym) unless @_added_options.include?(key.to_sym)
  define_singleton_method(key) do |args = nil|
    if !args
      instance_variable_get("@#{key}")
    else
      instance_variable_set("@#{key}", args)
    end
  end
end
list_options() click to toggle source
# File lib/core_refinements/Object/options.rb, line 18
def list_options
  return @_added_options ||= nil
end