Class: Mastodon::Collection
- Inherits:
-
Object
- Object
- Mastodon::Collection
- Includes:
- Enumerable
- Defined in:
- lib/mastodon/collection.rb
Instance Method Summary collapse
- #each(start = 0) ⇒ Object
-
#initialize(items, klass) ⇒ Collection
constructor
A new instance of Collection.
- #last ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(items, klass) ⇒ Collection
Returns a new instance of Collection.
5 6 7 |
# File 'lib/mastodon/collection.rb', line 5 def initialize(items, klass) @collection = items.map { |attributes| klass.new(attributes) } end |
Instance Method Details
#each(start = 0) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/mastodon/collection.rb', line 9 def each(start = 0) return to_enum(:each, start) unless block_given? Array(@collection[start..-1]).each do |element| yield(element) end self end |
#last ⇒ Object
23 24 25 |
# File 'lib/mastodon/collection.rb', line 23 def last @collection.last end |
#size ⇒ Object
19 20 21 |
# File 'lib/mastodon/collection.rb', line 19 def size @collection.size end |