Sha256: aebe631e808d7a8b59eab0bc92e9bc8df5a81fa246d9f49bc68683d7855e6161

Contents?: true

Size: 345 Bytes

Versions: 44

Compression:

Stored size: 345 Bytes

Contents

require 'enumerator'

class Array
  def chunk(pieces)
    q, r = length.divmod(pieces)
    (0..pieces).map { |i| i * q + [r, i].min }.enum_cons(2) \
    .map { |a, b| slice(a...b) }
  end
  
  def shuffle
    sort_by { rand }
  end

  def shuffle!
    self.replace shuffle
  end
  
  def random
    idx = Kernel.rand(size)
    at(idx)
  end
end

Version data entries

44 entries across 44 versions & 3 rubygems

Version Path
sunrise-cms-0.6.11 lib/sunrise/core_ext/array.rb
sunrise-cms-0.6.10 lib/sunrise/core_ext/array.rb
sunrise-cms-0.6.9 lib/sunrise/core_ext/array.rb
sunrise-cms-0.6.8 lib/sunrise/core_ext/array.rb
sunrise-cms-0.6.7 lib/sunrise/core_ext/array.rb
sunrise-cms-0.6.6 lib/sunrise/core_ext/array.rb
sunrise-cms-0.6.5 lib/sunrise/core_ext/array.rb
sunrise-cms-0.6.4 lib/sunrise/core_ext/array.rb
sunrise-cms-0.6.3 lib/sunrise/core_ext/array.rb
sunrise-cms-0.6.2 lib/sunrise/core_ext/array.rb
sunrise-cms-0.6.1 lib/sunrise/core_ext/array.rb
sunrise-cms-0.6.0 lib/sunrise/core_ext/array.rb
sunrise-cms-0.5.3 lib/sunrise/core_ext/array.rb
sunrise-cms-0.5.2 lib/sunrise/core_ext/array.rb
sunrise-cms-0.5.1 lib/sunrise/core_ext/array.rb
sunrise-cms-0.5.0 lib/sunrise/core_ext/array.rb
sunrise-cms-0.5.0.rc5 lib/sunrise/core_ext/array.rb
sunrise-cms-0.5.0.rc4 lib/sunrise/core_ext/array.rb
sunrise-cms-0.5.0.rc3 lib/sunrise/core_ext/array.rb
sunrise-cms-0.5.0.rc2 lib/sunrise/core_ext/array.rb