Class: Fetching::FetchingArray
- Includes:
- Enumerable, ArrayMethods
- Defined in:
- lib/fetching/fetching_array.rb
Defined Under Namespace
Modules: ArrayMethods
Constant Summary
Constants inherited from Fetching
Instance Method Summary collapse
Methods included from ArrayMethods
#empty?, #length, #reverse, #shuffle, #sort, #sort_by, #values_at
Methods inherited from Fetching
#==, from, from_json, #hash, #initialize, #inspect, #to_fetching, #to_s
Constructor Details
This class inherits a constructor from Fetching
Instance Method Details
#[](*args) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fetching/fetching_array.rb', line 6 def [](*args) if args.length == 1 && args.first.is_a?(Integer) Fetching.from @table.fetch(args.first) else values_at(*args) end end |
#each ⇒ Object
14 15 16 17 18 |
# File 'lib/fetching/fetching_array.rb', line 14 def each @table.each_index do |i| yield self[i] end end |
#first(num = 0) ⇒ Object
20 21 22 23 24 |
# File 'lib/fetching/fetching_array.rb', line 20 def first(num = 0) return self[0] if num.zero? Array.new(num) { |i| self[i] } end |