Module: Lean::Attributes::Basic

Defined in:
lib/lean-attributes/attributes.rb

Overview

Includes basic methods for defining attributes without polluting the inclusive class with coercion or initialization methods. You may mean to use Lean::Attributes.

See Also:

Since:

  • 0.1.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds ‘.attribute` definition only

See Also:

Since:

  • 0.1.0



29
30
31
32
33
# File 'lib/lean-attributes/attributes.rb', line 29

def self.included(base)
  base.class_eval do
    extend ClassMethods
  end
end

Instance Method Details

#attributesHash

Returns a hash containing defined attribute names and their values.

Returns:

  • (Hash)

    defined attributes and their values

Since:

  • 0.2.0



41
42
43
44
45
46
# File 'lib/lean-attributes/attributes.rb', line 41

def attributes
  @attributes ||=
    self.class.defined_attributes.each_with_object({}) do |attr, memo|
      memo[attr] = send(attr)
    end
end