SixArm.com SixArm.com » Ruby » Array slice methods: #slice_by_size and #sllice_by_share
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.yardoc
doc
lib
test
.codeclimate.yml
.document
.gemtest
.gitattributes
.gitignore
.rspec
.travis.yml
CHANGES.md
CONTRIBUTING.md
Gemfile
LICENSE.md
README.md
Rakefile
VERSION
sixarm_ruby_array_slice-2.1.7-sha512.txt
sixarm_ruby_array_slice-2.1.7.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

Gem

Run this command in your shell or terminal:

gem install sixarm_ruby_array_slice

Or add this to your Gemfile:

gem 'sixarm_ruby_array_slice'

Require

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]]