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.91 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.90 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.89 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.88 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.87 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.86 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.85 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.84 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.83 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.82 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.81 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.80 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.79 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.78 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.77 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.76 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.75 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.74 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.73 lib/open_classes/array/together_delete.rb
tbpgr_utils-0.0.72 lib/open_classes/array/together_delete.rb