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.91 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.90 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.89 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.88 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.87 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.86 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.85 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.84 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.83 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.82 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.81 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.80 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.79 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.78 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.77 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.76 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.75 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.74 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.73 lib/open_classes/array/together_insert.rb
tbpgr_utils-0.0.72 lib/open_classes/array/together_insert.rb