class Hashme::CastedArray

The Hashme CastedArray is a special object wrapper that allows other Model's or Objects to be stored in an array, but maintain casted ownership.

Adding objects will automatically assign the Array's owner, as opposed to the array itself.

Attributes

property[R]

Public Class Methods

new(property, owner, values = []) click to toggle source
# File lib/hashme/casted_array.rb, line 24
def initialize(property, owner, values = [])
  @_array = []
  @property = property
  if values.respond_to?(:each)
    values.each do |value|
      self.push(value)
    end
  end
end

Public Instance Methods

<<(obj) click to toggle source
# File lib/hashme/casted_array.rb, line 34
def <<(obj)
  @_array << instantiate_and_build(obj)
end
[](index) click to toggle source
# File lib/hashme/casted_array.rb, line 46
def [] index
  @_array[index]
end
[]=(index, obj) click to toggle source
# File lib/hashme/casted_array.rb, line 50
def []= index, obj
  @_array[index] = instantiate_and_build(obj)
end
push(obj) click to toggle source
# File lib/hashme/casted_array.rb, line 38
def push(obj)
  @_array.push(instantiate_and_build(obj))
end
unshift(obj) click to toggle source
# File lib/hashme/casted_array.rb, line 42
def unshift(obj)
  @_array.unshift(instantiate_and_build(obj))
end

Protected Instance Methods

instantiate_and_build(obj) click to toggle source
# File lib/hashme/casted_array.rb, line 56
def instantiate_and_build(obj)
  property.build(self, obj)
end