Class: Array
- Inherits:
-
Object
show all
- Defined in:
- lib/inline_acceleration.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
94
95
96
97
98
99
100
101
102
|
# File 'lib/inline_acceleration.rb', line 94
def method_missing(name, *args, &block)
if name.to_s[-1..-1] == 's'
method_name = name.to_s[0..-2].to_sym
if size == 0 || self[0].respond_to?(method_name)
return map_method_results(method_name)
end
end
throw_method_missing(name, args, &block)
end
|
Instance Method Details
#all_indices ⇒ Object
50
51
52
|
# File 'lib/inline_acceleration.rb', line 50
def all_indices
(0...self.size).to_a
end
|
#assigned_indices ⇒ Object
54
55
56
|
# File 'lib/inline_acceleration.rb', line 54
def assigned_indices
all_indices.reject { |i| self[i].nil? }
end
|
#map_method_results(method_name) ⇒ Object
85
86
87
|
# File 'lib/inline_acceleration.rb', line 85
def map_method_results(method_name)
self.map { |item| item.send(method_name) }
end
|
#map_method_results!(method_name) ⇒ Object
89
90
91
|
# File 'lib/inline_acceleration.rb', line 89
def map_method_results!(method_name)
self.map! { |item| item.send(method_name) }
end
|
#map_with_indices(target = []) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/inline_acceleration.rb', line 74
def map_with_indices(target = [])
self.each_index do |index|
target[index] = yield(self[index], index)
end
target
end
|
#map_with_indices! ⇒ Object
81
82
83
|
# File 'lib/inline_acceleration.rb', line 81
def map_with_indices!
self.map_with_indices(self)
end
|
#postfix(str) ⇒ Object
66
67
68
|
# File 'lib/inline_acceleration.rb', line 66
def postfix(str)
self.map { |item| "#{item}#{str}" }
end
|
#postfix!(str) ⇒ Object
70
71
72
|
# File 'lib/inline_acceleration.rb', line 70
def postfix!(str)
self.map! { |item| "#{item}#{str}" }
end
|
#prefix(str) ⇒ Object
58
59
60
|
# File 'lib/inline_acceleration.rb', line 58
def prefix(str)
self.map { |item| "#{str}#{item}" }
end
|
#prefix!(str) ⇒ Object
62
63
64
|
# File 'lib/inline_acceleration.rb', line 62
def prefix!(str)
self.map! { |item| "#{str}#{item}" }
end
|
#reject_nils ⇒ Object
104
105
106
|
# File 'lib/inline_acceleration.rb', line 104
def reject_nils
self.reject { |item| item.nil? }
end
|
#reject_nils! ⇒ Object
108
109
110
|
# File 'lib/inline_acceleration.rb', line 108
def reject_nils!
self.reject! { |item| item.nil? }
end
|
#throw_method_missing ⇒ Object
93
|
# File 'lib/inline_acceleration.rb', line 93
alias_method :throw_method_missing, :method_missing
|