Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

ActiveSupport | Array#split

概要

Array#split

詳細

Array#split について

Array#split

文字列のsplitの配列版

サンプル

# encoding: utf-8
require 'active_support/core_ext/array/grouping'
require 'tbpgr_utils'

I18n.enforce_available_locales = true
ary = [2, 1, 3, 1, 4]
bulk_puts_eval binding, <<-EOS
ary.split 1
ary.split 2
ary.split 3
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

ary.split 1 # => [[2], [3], [4]]
ary.split 2 # => [[], [1, 3, 1, 4]]
ary.split 3 # => [[2, 1], [1, 4]]