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.131 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.130 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.129 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.128 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.127 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.126 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.125 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.124 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.123 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.122 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.121 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.120 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.119 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.118 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.117 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.116 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.115 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.114 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.113 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.112 lib/open_classes/array/together_delete.rb