Sha256: de825a9a346c2dd1ef04d056f6136bff54412a9b077698627c9d1d2f670c13a1

Contents?: true

Size: 984 Bytes

Versions: 115

Compression:

Stored size: 984 Bytes

Contents

# encoding: utf-8
require 'open_classes/object'
require 'open_classes/module'
require 'open_classes/array/together_helper'

# Array
class Array
  include TogetherHelper

  # Arrays bulk insert.
  #
  # together_insert has alias :tinsert
  #
  # both insert exist case
  #   lists = [[*1..5], [*5..9]]
  #   ret = lists.together_insert(1, 55, 66)
  #   print ret # => [[1, 55, 66, 2, 3, 4, 5], [5, 55, 66, 6, 7, 8, 9]]
  #
  # both insert exist and minus index case
  #   lists = [[*1..5], [*5..9]]
  #   ret = lists.together_insert(-2, 55, 66)
  #   print ret # => [[1, 2, 3, 4, 55, 66, 5], [5, 6, 7, 8, 55, 66, 9]]
  #
  # both insert exist case
  #   lists = [[*1..5], [*5..9]]
  #   ret = lists.together_insert(6, 55, 66)
  #   print ret # => [[1, 2, 3, 4, 5, nil, 55, 66], [5, 6, 7, 8, 9, nil, 55, 66]],
  def together_insert(index, *args)
    if_not_contain_array_rails_type_error
    each { |list|list.insert(index, *args) }
  end

  alias_method :tinsert, :together_insert
end

Version data entries

115 entries across 115 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.151 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.150 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.149 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.148 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.147 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.146 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.145 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.144 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.143 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.142 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.141 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.140 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.139 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.138 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.137 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.136 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.135 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.134 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.133 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.132 lib/open_classes/array/together_insert.rb