Class: LazyArray
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/extlib/lazy_array.rb
Overview
borrowed partially from StrokeDB
Constant Summary
collapse
- RETURN_SELF =
these methods should return self or nil
[ :<<, :clear, :concat, :collect!, :each, :each_index,
:each_with_index, :freeze, :insert, :map!, :push, :replace,
:reject!, :reverse!, :reverse_each, :sort!, :unshift ]
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
delegate any not-explicitly-handled methods to @array, if possible. this is handy for handling methods mixed-into Array like group_by
98
99
100
101
102
103
104
105
|
# File 'lib/extlib/lazy_array.rb', line 98
def method_missing(method, *args, &block)
if @array.respond_to?(method)
lazy_load
@array.send(method, *args, &block)
else
super
end
end
|
Instance Method Details
36
37
38
39
40
|
# File 'lib/extlib/lazy_array.rb', line 36
def clear
mark_loaded
@array.clear
self
end
|
#eql?(other) ⇒ Boolean
Also known as:
==
42
43
44
45
|
# File 'lib/extlib/lazy_array.rb', line 42
def eql?(other)
lazy_load
@array.eql?(other.entries)
end
|
#load_with(&block) ⇒ Object
49
50
51
52
|
# File 'lib/extlib/lazy_array.rb', line 49
def load_with(&block)
@load_with_proc = block
self
end
|
#loaded? ⇒ Boolean
54
55
56
|
# File 'lib/extlib/lazy_array.rb', line 54
def loaded?
@loaded == true
end
|
#replace(other) ⇒ Object
30
31
32
33
34
|
# File 'lib/extlib/lazy_array.rb', line 30
def replace(other)
mark_loaded
@array.replace(other.entries)
self
end
|
#respond_to?(method, include_private = false) ⇒ Boolean
64
65
66
|
# File 'lib/extlib/lazy_array.rb', line 64
def respond_to?(method, include_private = false)
super || @array.respond_to?(method, include_private)
end
|
68
69
70
|
# File 'lib/extlib/lazy_array.rb', line 68
def to_proc
@load_with_proc
end
|
58
59
60
61
62
|
# File 'lib/extlib/lazy_array.rb', line 58
def unload
clear
@loaded = false
self
end
|