Class: Croudia::Object::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/croudia/object/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
# File 'lib/croudia/object/base.rb', line 6

def initialize(attrs = {})
  @attrs = attrs || {}
  @attrs.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



4
5
6
# File 'lib/croudia/object/base.rb', line 4

def attrs
  @attrs
end

Class Method Details

.attr_reader_as_array_object(attribute, object) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/croudia/object/base.rb', line 20

def attr_reader_as_array_object(attribute, object)
  define_method(attribute.to_s) do
    @attr[attribute.to_s].map do |obj|
      Object.const_get(object.to_s).new(obj)
    end
  end
end

.attr_reader_as_object(attribute, object) ⇒ Object



14
15
16
17
18
# File 'lib/croudia/object/base.rb', line 14

def attr_reader_as_object(attribute, object)
  define_method(attribute.to_s) do
    Object.const_get(object.to_s).new(@attrs[attribute.to_s])
  end
end