class MetalArchives::Collection
Enumerable collection over a paginated resource
Public Class Methods
new(proc)
click to toggle source
Construct a new Collection
proc
-
Proc
orlambda
, called repeatedly when iterating. Should return an array of results (stateful), should return an empty array when there are no results left.
# File lib/metal_archives/collection.rb, line 17 def initialize(proc) @proc = proc end
Public Instance Methods
each() { |item| ... }
click to toggle source
Calls the given block once for each element, passing that element as a parameter. If no block is given, an Enumerator is returned.
# File lib/metal_archives/collection.rb, line 25 def each return to_enum :each unless block_given? loop do items = instance_exec(&@proc) items.each do |item| yield item end break if items.empty? end end
empty?()
click to toggle source
# File lib/metal_archives/collection.rb, line 39 def empty? first.nil? end