Sha256: 65715c2844801b2006ad46587abbdd09fbe77742c3000157ea1a7b126a95f295

Contents?: true

Size: 1.23 KB

Versions: 115

Compression:

Stored size: 1.23 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.
  #
  # together_delete has alias :tdelete
  #
  # if delete target is exist
  #   child1 = [1, 2, 3, 4]
  #   child2 = [2, 3, 4, 5]
  #   lists = [child1, child2]
  #   ret = lists.together_delete 2
  #   print ret # => 2
  #   print lists # => output [[1, 3, 4], [3, 4, 5]]
  #
  # if delete target is not exist
  #   child1 = [1, 2, 3, 4]
  #   child2 = [2, 3, 4, 5]
  #   lists = [child1, child2]
  #   ret = lists.together_delete 6
  #   print ret # => nil
  #   print lists # => output [[1, 2, 3, 4], [2, 3, 4, 5]]
  #
  # if delete target is not exist and use block
  #   child1 = [1, 2, 3, 4]
  #   child2 = [2, 3, 4, 5]
  #   lists = [child1, child2]
  #   ret = lists.together_delete(6) { 999 }
  #   print ret # => 999
  #   print lists # => output [[1, 2, 3, 4], [2, 3, 4, 5]]
  def together_delete(value)
    if_not_contain_array_rails_type_error
    ret = []
    each { |list|ret << list.delete(value) }
    default_return = block_given? ? yield : nil
    ret.compact.size == 0 ? default_return : value
  end

  alias_method :tdelete, :together_delete
end

Version data entries

115 entries across 115 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.111 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.110 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.109 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.108 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.107 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.106 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.105 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.104 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.103 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.102 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.101 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.100 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.99 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.98 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.97 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.96 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.95 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.94 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.93 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.92 lib/open_classes/array/together_delete.rb