class Anima::Attribute

An attribute

Attributes

instance_variable_name[R]

Return instance variable name

@return [Symbol]

name[R]

Return attribute name

@return [Symbol]

Public Class Methods

new(name) click to toggle source

Initialize attribute

@param [Symbol] name

# File lib/anima/attribute.rb, line 9
def initialize(name)
  @name, @instance_variable_name = name, :"@#{name}"
end

Public Instance Methods

get(object) click to toggle source

Get attribute value from object

@param [Object] object

@return [Object]

# File lib/anima/attribute.rb, line 38
def get(object)
  object.public_send(name)
end
load(object, attributes) click to toggle source

Load attribute

@param [Object] object @param [Hash] attributes

@return [self]

# File lib/anima/attribute.rb, line 29
def load(object, attributes)
  set(object, attributes.fetch(name))
end
set(object, value) click to toggle source

Set attribute value in object

@param [Object] object @param [Object] value

@return [self]

# File lib/anima/attribute.rb, line 48
def set(object, value)
  object.instance_variable_set(instance_variable_name, value)

  self
end