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.71 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.70 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.69 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.68 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.67 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.66 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.65 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.64 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.63 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.62 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.61 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.60 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.59 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.58 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.57 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.56 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.55 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.54 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.53 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.52 lib/open_classes/array/together_delete.rb