Sha256: 568f5ff8760d7d04b32b5eb1b24b8bf8fce0a555bf10f3b4ebbf438035504ae9
Contents?: true
Size: 824 Bytes
Versions: 1
Compression:
Stored size: 824 Bytes
Contents
class Array def mean sum / size end def count(&action) return size unless block_given? self.inject(0){ |memo,item| memo += 1 if action.call(item); memo } end def compakt self.reject do |i| (i.respond_to?(:length) && i.length == 0) || (i.respond_to?(:match) && i.match(/^\s+$/)) end end def random(num_elements = 1) num_elements == 1 ? self[Kernel.rand(size)] : sort_by{ Kernel.rand }.slice(0...num_elements) end def randomized sort_by { rand } end # Return subarrays of random length between a min and max def sections(min_size, max_size) sects = [] offset = 0 while offset < size next_size = (min_size..max_size).random.to_i sects << self[offset..offset+next_size] offset += next_size + 1 end sects end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bootstripe-0.2.9 | lib/bootstripe/array_additions.rb |