Module: Anima::InstanceMethods

Defined in:
lib/anima.rb

Overview

Static instance methods for anima infected classes

Instance Method Summary collapse

Instance Method Details

#initialize(attributes) ⇒ undefined

Initialize an anima infected object

Parameters:

  • attributes (#to_h)

    a hash that matches anima defined attributes

Returns:

  • (undefined)


110
111
112
# File 'lib/anima.rb', line 110

def initialize(attributes)
  self.class.anima.initialize_instance(self, attributes)
end

#to_hHash

Return a hash representation of an anima infected object

Returns:

  • (Hash)


119
120
121
# File 'lib/anima.rb', line 119

def to_h
  self.class.anima.attributes_hash(self)
end

#with(attributes) ⇒ Anima

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.

Return updated instance

Examples:

klass = Class.new do
  include Anima.new(:foo, :bar)
end

foo = klass.new(:foo => 1, :bar => 2)
updated = foo.with(:foo => 3)
updated.foo # => 3
updated.bar # => 2

Parameters:

  • attributes (Hash)

Returns:



141
142
143
# File 'lib/anima.rb', line 141

def with(attributes)
  self.class.new(to_h.update(attributes))
end