Sha256: 3fd0aee0b7c249fff09cfe8e1c06abba407a3467e251368939b15d6a18091406

Contents?: true

Size: 1.17 KB

Versions: 115

Compression:

Stored size: 1.17 KB

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 delete_at.
  #
  # together_delete_at has alias :tdelete_at
  #
  # if delete_at target is exist
  #   child1 = [1, 2, 3, 4]
  #   child2 = [2, 3, 4, 5]
  #   lists = [child1, child2]
  #   ret = lists.together_delete_at 2
  #   print ret # => [3, 4]
  #   print lists # => output [[1, 2, 4], [2, 3, 5]]
  #
  # if delete_at target is not exist
  #   child1 = [1, 2, 3, 4]
  #   child2 = [2, 3, 4, 5]
  #   lists = [child1, child2]
  #   ret = lists.together_delete_at 6
  #   print ret # => [nil, nil]
  #   print lists # => output [[1, 2, 3, 4], [2, 3, 4, 5]]
  #
  # if delete_at target is exist(minus index)
  #   child1 = [1, 2, 3, 4]
  #   child2 = [2, 3, 4, 5]
  #   lists = [child1, child2]
  #   ret = lists.together_delete_at -3
  #   print ret # => [2, 3]
  #   print lists # => output [[1, 3, 4], [2, 4, 5]]
  def together_delete_at(index)
    if_not_contain_array_rails_type_error
    reduce([]) { |ret, list|ret << list.delete_at(index) }
  end

  alias_method :tdelete_at, :together_delete_at
end

Version data entries

115 entries across 115 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.71 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.70 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.69 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.68 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.67 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.66 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.65 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.64 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.63 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.62 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.61 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.60 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.59 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.58 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.57 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.56 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.55 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.54 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.53 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.52 lib/open_classes/array/together_delete_at.rb