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.5.0.rc1 lib/sunrise/core_ext/array.rb
sunrise-cms-0.4.2 lib/sunrise/core_ext/array.rb
sunrise-cms-0.4.1 lib/sunrise/core_ext/array.rb
sunrise-cms-0.4.0 lib/sunrise/core_ext/array.rb
sunrise-cms-0.3.3 lib/sunrise/core_ext/array.rb
sunrise-cms-0.3.2 lib/sunrise/core_ext/array.rb
sunrise-cms-0.3.1 lib/sunrise/core_ext/array.rb
sunrise-cms-0.3.0 lib/sunrise/core_ext/array.rb
sunrise-cms-0.3.0.rc2 lib/sunrise/core_ext/array.rb
sunrise-cms-0.3.0.rc lib/sunrise/core_ext/array.rb
sunrise-core-0.2.2 lib/sunrise/core_ext/array.rb
sunrise-core-0.2.1 lib/sunrise/core_ext/array.rb
sunrise-core-0.2.0 lib/sunrise/core_ext/array.rb
sunrise-core-0.1.5 lib/sunrise/core_ext/array.rb
sunrise-core-0.1.4 lib/sunrise/core_ext/array.rb
sunrise-core-0.1.3 lib/sunrise/core_ext/array.rb
sunrise-core-0.1.2 lib/sunrise/core_ext/array.rb
sunrise-core-0.1.1 lib/sunrise/core_ext/array.rb
sunrise-core-0.1.0 lib/sunrise/core_ext/array.rb
freeberry-0.3.0 lib/freeberry/core_ext/array.rb