Class: Array
Overview
Array extension.
Instance Method Summary collapse
- #array? ⇒ Boolean
- #avg ⇒ Object (also: #average)
- #clean(value = nil) ⇒ Object
- #clean!(value = nil) ⇒ Object
- #eighth ⇒ Object
- #fifth ⇒ Object
- #fourth ⇒ Object
- #merge!(*arrays) ⇒ Object
- #remove!(&block) ⇒ Object
- #second ⇒ Object
- #seventh ⇒ Object
- #sixth ⇒ Object
- #sum ⇒ Object
- #third ⇒ Object
- #to_h(mode = nil) ⇒ Object
- #to_set ⇒ Object
Instance Method Details
#array? ⇒ Boolean
263 264 265 |
# File 'lib/hash-utils/array.rb', line 263 def array? true end |
#avg ⇒ Object Also known as: average
246 247 248 |
# File 'lib/hash-utils/array.rb', line 246 def avg self.sum.to_f / self.length end |
#clean(value = nil) ⇒ Object
278 279 280 |
# File 'lib/hash-utils/array.rb', line 278 def clean(value = nil) self.reject { |v| v === value } end |
#clean!(value = nil) ⇒ Object
293 294 295 |
# File 'lib/hash-utils/array.rb', line 293 def clean!(value = nil) self.reject! { |v| v === value } end |
#eighth ⇒ Object
194 195 196 |
# File 'lib/hash-utils/array.rb', line 194 def eighth self[7] end |
#fifth ⇒ Object
155 156 157 |
# File 'lib/hash-utils/array.rb', line 155 def fifth self[4] end |
#fourth ⇒ Object
142 143 144 |
# File 'lib/hash-utils/array.rb', line 142 def fourth self[3] end |
#merge!(*arrays) ⇒ Object
101 102 103 104 105 |
# File 'lib/hash-utils/array.rb', line 101 def merge!(*arrays) arrays.flatten! 1 arrays.each { |i| self << i } self end |
#remove!(&block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hash-utils/array.rb', line 25 def remove!(&block) result = [ ] self.reject! do |v| if block.call(v) result << v true else false end end return result end |
#second ⇒ Object
116 117 118 |
# File 'lib/hash-utils/array.rb', line 116 def second self[1] end |
#seventh ⇒ Object
181 182 183 |
# File 'lib/hash-utils/array.rb', line 181 def seventh self[6] end |
#sixth ⇒ Object
168 169 170 |
# File 'lib/hash-utils/array.rb', line 168 def sixth self[5] end |
#sum ⇒ Object
215 216 217 |
# File 'lib/hash-utils/array.rb', line 215 def sum self.inject(:+) end |
#third ⇒ Object
129 130 131 |
# File 'lib/hash-utils/array.rb', line 129 def third self[2] end |
#to_h(mode = nil) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/hash-utils/array.rb', line 75 def to_h(mode = nil) if mode == :flat Hash[*self] else Hash[self] end end |
#to_set ⇒ Object
306 307 308 |
# File 'lib/hash-utils/array.rb', line 306 def to_set Set::new(self) end |