Class: Ru::Array
- Inherits:
-
Object
show all
- Defined in:
- lib/ru/array.rb
Instance Method Summary
collapse
Constructor Details
#initialize(array) ⇒ Array
Returns a new instance of Array.
3
4
5
|
# File 'lib/ru/array.rb', line 3
def initialize(array)
@data = array.to_a
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
71
72
73
|
# File 'lib/ru/array.rb', line 71
def method_missing(method, *args, &block)
delegate_to_array(method, *args, &block)
end
|
Instance Method Details
#==(other) ⇒ Object
67
68
69
|
# File 'lib/ru/array.rb', line 67
def ==(other)
self.to_a == other.to_a
end
|
#each_line ⇒ Object
7
8
9
|
# File 'lib/ru/array.rb', line 7
def each_line
Ru::Iterator.new(self)
end
|
#files ⇒ Object
11
12
13
14
15
16
|
# File 'lib/ru/array.rb', line 11
def files
@data.map! do |line|
Ru::File.new(line)
end
self
end
|
18
19
20
21
22
23
|
# File 'lib/ru/array.rb', line 18
def format(format='l')
@data.map! do |item|
item.format(format)
end
self
end
|
#grep(pattern) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/ru/array.rb', line 25
def grep(pattern)
if pattern.kind_of?(String)
pattern = Regexp.new(pattern)
end
select! do |item|
item.to_s =~ pattern
end
self
end
|
#map(method = nil, *args, &block) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/ru/array.rb', line 35
def map(method=nil, *args, &block)
if method.nil? && !block_given?
to_a.map
elsif method.nil?
array = to_a.map(&block)
self.class.new(array)
else
array = to_a.map { |item| item.send(method, *args) }
self.class.new(array)
end
end
|
#select(*args, &block) ⇒ Object
47
48
49
|
# File 'lib/ru/array.rb', line 47
def select(*args, &block)
delegate_to_array(:select, *args, &block)
end
|
#to_a ⇒ Object
51
52
53
|
# File 'lib/ru/array.rb', line 51
def to_a
@data
end
|
#to_ary ⇒ Object
55
56
57
|
# File 'lib/ru/array.rb', line 55
def to_ary
to_a
end
|
#to_s ⇒ Object
59
60
61
|
# File 'lib/ru/array.rb', line 59
def to_s
self.to_a.join("\n")
end
|
#to_self ⇒ Object
63
64
65
|
# File 'lib/ru/array.rb', line 63
def to_self
self
end
|