Module: Cura::Attributes::HasAttributes

Overview

Adds the ‘update_attributes` method.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



38
39
40
# File 'lib/cura/attributes/has_attributes.rb', line 38

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.



47
48
49
50
51
# File 'lib/cura/attributes/has_attributes.rb', line 47

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

  super
end

#update_attributes(attributes = {}) ⇒ Hash

Update any attributes on this object.

Parameters:

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

Returns:

  • (Hash)

    The attributes.



57
58
59
60
61
# File 'lib/cura/attributes/has_attributes.rb', line 57

def update_attributes(attributes={})
  attributes = convert_attributes(attributes)

  attributes.each { |name, value| send("#{name}=", value) }
end