Sha256: f2aac56e9931c3d5f7c6e4494617b1fda56256db4181a72ceea914af82f91a61

Contents?: true

Size: 1.06 KB

Versions: 115

Compression:

Stored size: 1.06 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_if.
  #
  # together_delete_if has alias :tdelete_if
  #
  # if delete_if target is exist. return self.
  #   lists = [[1, 2, 3, 4], [6, 4, 6, 8]]
  #   ret = lists.together_delete_if {|first, second|(first + second).odd?}
  #   print ret # => [[2, 4], [4, 8]]
  #
  # if delete_if target is not exist. return nil.
  #   lists = [[2, 2, 4, 4], [6, 4, 6, 8]]
  #   ret = lists.together_delete_if {|first, second|(first + second).odd?}
  #   print ret # => nil
  def together_delete_if(&block)
    if_not_contain_array_rails_type_error
    have_deleted = false
    first.each_with_index do |i_v, i|
      eval_each_str = get_args_str_for_together i
      is_delete = instance_eval "yield(#{eval_each_str})"
      if is_delete
        each { |e|e.delete_at i }
        have_deleted = true
      end
    end
    have_deleted ? self : nil
  end

  alias_method :tdelete_if, :together_delete_if
end

Version data entries

115 entries across 115 versions & 1 rubygems

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