Class: Ru::Iterator
- Inherits:
-
Object
show all
- Defined in:
- lib/ru/iterator.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(enum) ⇒ Iterator
Returns a new instance of Iterator.
15
16
17
|
# File 'lib/ru/iterator.rb', line 15
def initialize(enum)
@enum = enum
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
41
42
43
|
# File 'lib/ru/iterator.rb', line 41
def method_missing(method, *args, &block)
map_method(method, *args, &block)
end
|
Class Method Details
.redefined_methods ⇒ Object
4
5
6
7
8
9
10
11
12
|
# File 'lib/ru/iterator.rb', line 4
def redefined_methods
@redefined_methods ||= begin
preserved_methods = %{initialize method_missing respond_to? to_a}
[].public_methods.select do |method|
method = method.to_s
method =~ /^[a-z]/ && !preserved_methods.include?(method)
end
end
end
|
Instance Method Details
#to_a ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/ru/iterator.rb', line 19
def to_a
case @enum
when ::Array
Ru::Array.new(@enum)
when Ru::Array
@enum
when Ru::Stream
@enum.to_a
end
end
|
#to_stdout ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/ru/iterator.rb', line 30
def to_stdout
case @enum
when ::Array
@enum.join("\n")
else
@enum.to_s
end
end
|