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.151 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.150 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.149 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.148 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.147 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.146 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.145 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.144 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.143 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.142 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.141 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.140 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.139 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.138 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.137 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.136 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.135 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.134 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.133 lib/open_classes/array/together_delete_at.rb
tbpgr_utils-0.0.132 lib/open_classes/array/together_delete_at.rb