Module: BN::Helpers::HasAttributes

Included in:
API::Base, Entity::Base, Error::Base
Defined in:
lib/bn/helpers/has_attributes.rb

Overview

Adds the ‘update_attributes` method and `attribute` class method.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



21
22
23
# File 'lib/bn/helpers/has_attributes.rb', line 21

def included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#initialize(attributes = {}) ⇒ Object

Initialize this object by optionally updating attributes with a Hash.

Parameters:

  • attributes (#to_h) (defaults to: {})

    Attributes to set after initializing.



29
30
31
# File 'lib/bn/helpers/has_attributes.rb', line 29

def initialize(attributes={})
  update_attributes(attributes)
end

#update_attributes(attributes = {}) ⇒ Hash

Update any attributes on this object.

Parameters:

  • attributes (#to_h) (defaults to: {})

Returns:

  • (Hash)

    The attributes.



37
38
39
40
41
42
# File 'lib/bn/helpers/has_attributes.rb', line 37

def update_attributes(attributes={})
  attributes = attributes.to_h
  attributes.each { |name, value| send("#{name}=", value) }

  attributes
end