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.111 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.110 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.109 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.108 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.107 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.106 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.105 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.104 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.103 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.102 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.101 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.100 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.99 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.98 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.97 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.96 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.95 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.94 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.93 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.92 lib/open_classes/array/together_insert.rb