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