Method: Braintree::ResourceCollection#first

Defined in:
lib/braintree/resource_collection.rb

#first(amount = 1) ⇒ Object

Returns the first or the first N items in the collection or nil if the collection is empty



26
27
28
29
30
31
32
33
# File 'lib/braintree/resource_collection.rb', line 26

def first(amount = 1)
  return nil if @ids.empty?
  return @paging_block.call([@ids.first]).first if amount == 1

  @ids.first(amount).each_slice(@page_size).flat_map do |page_of_ids|
    @paging_block.call(page_of_ids)
  end
end