Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/clearbooks/core_ext/array.rb
Class Method Summary collapse
Class Method Details
.%(len) ⇒ Object
now e.g. this is possible
- “foo0”, “foo1”, “foo2”, “foo3”, “foo4”, “foo5”, “foo6”, “foo7”, “foo8”, “foo9”, “foo10”
- [“foo0”, “foo1”, “foo2”], [“foo3”, “foo4”, “foo5”], [“foo6”, “foo7”, “foo8”], [“foo9”, “foo10”]
28 29 30 31 32 33 34 |
# File 'lib/clearbooks/core_ext/array.rb', line 28 def %(len) inject([]) do |array, x| array << [] if [*array.last].nitems % len == 0 array.last << x array end end |
.delete_unless(&block) ⇒ Object
13 14 15 |
# File 'lib/clearbooks/core_ext/array.rb', line 13 def delete_unless &block delete_if{ |element| not block.call( element ) } end |
.mean ⇒ Object
43 44 45 |
# File 'lib/clearbooks/core_ext/array.rb', line 43 def mean sum / size end |
.sum ⇒ Object
37 38 39 |
# File 'lib/clearbooks/core_ext/array.rb', line 37 def sum inject( nil ) { |sum,x| sum ? sum+x : x } end |