SixArm.com SixArm.com » Ruby » Array slice methods: #slice_by_size and #sllice_by_share
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.yardoc
coverage
doc
lib
test
.codeclimate.yml
.document
.gemtest
.gitattributes
.gitignore
.rspec
.travis.yml
CHANGES.md
CONTRIBUTING.md
Gemfile
Gemfile.lock
LICENSE.md
README.md
Rakefile
VERSION
sixarm_ruby_array_slice-2.1.6-sha512.txt
sixarm_ruby_array_slice-2.1.6.gem
sixarm_ruby_array_slice.gemspec

README.md

SixArm.com » Ruby »
Array slice methods by size and share

Gem Version Build Status Code Climate Coverage Status

Introduction

Array slice methods:

  • #slice_by_share: divides an array into a given number of slices
  • #slice_by_size: divides an array into a slices of a given size

For docs go to http://sixarm.com/sixarm_ruby_array_slice/doc

Want to help? We're happy to get pull requests.

Install

To install using a Gemfile, add this:

gem "sixarm_ruby_array_slice", ">= 2.1.6", "< 3"

To install using the command line, run this:

gem install sixarm_ruby_array_slice -v ">= 2.1.6, < 3"

To install using the command line with high security, run this:

wget http://sixarm.com/sixarm.pem
gem cert --add sixarm.pem && gem sources --add http://sixarm.com
gem install sixarm_ruby_array_slice -v ">= 2.1.6, < 3" --trust-policy HighSecurity

To require the gem in your code:

require "sixarm_ruby_array_slice"

Example

Example of both ways to slice:

[1,2,3,4,5,6,7,8].slice_by_size(2)
=> [[1,2],[3,4],[5,6],[7,8]]

[1,2,3,4,5,6,7,8].slice_by_share(2)
=> [[1,2,3,4],[5,6,7,8]]