Method: Inch::API::Options::Base.attribute

Defined in:
lib/inch/api/options/base.rb

.attribute(name, default = nil) ⇒ void

This method returns an undefined value.

Creates an attribute with an optional default value

Parameters:

  • name (Symbol)

    the name of the attribute

  • default (nil) (defaults to: nil)

    the default value of the attribute



11
12
13
14
15
16
17
18
# File 'lib/inch/api/options/base.rb', line 11

def attribute(name, default = nil)
  define_method(name) do
    instance_variable_get("@#{name}") || default
  end
  @attributes ||= {}
  @attributes[to_s] ||= []
  @attributes[to_s] << name
end