Method: JSONAPI::Collection#initialize

Defined in:
lib/easy/jsonapi/collection.rb

#initialize(arr_of_obj = [], item_type: Object) {|item| ... } ⇒ Collection

Assume collection is empty not innitialized with an array of objects. for block { |item| item }

Parameters:

  • arr_of_obj (Object) (defaults to: [])

    The objects to be stored

Yields:

  • (item)

    Determines what should be used as keys when storing objects in collection’s internal hash



12
13
14
15
16
17
18
19
20
21
# File 'lib/easy/jsonapi/collection.rb', line 12

def initialize(arr_of_obj = [], item_type: Object, &block)
  @item_type = item_type
  @collection = {}

  return unless (arr_of_obj != []) && block_given?

  arr_of_obj.each do |obj|
    add(obj, &block)
  end
end