Sha256: d9c3e10251587a13b9540a4209e1c06113663f69de1daec0151db91d5b93ac42

Contents?: true

Size: 1.21 KB

Versions: 114

Compression:

Stored size: 1.21 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 compact.(immutable)
  #
  # together_compact has alias :tcompact
  #
  # same elements size case
  #   alpha = ['a','b','c', nil,'d']
  #   numbers = [1, 2, nil, 3]
  #   lists = [alpha, numbers]
  #   ret = lists.together_compact
  #   print lists # => output [['a','b','c', nil,'d'], [1, 2, nil, 3]]
  #   print ret # => output [['a','b','c','d'], [1, 2, 3]]
  def together_compact
    if_not_contain_array_rails_type_error
    reduce([]) { |ret, list|ret << list.compact }
  end

  # Arrays bulk compact!.(mutable)
  #
  # together_compact! has alias :tcompact!
  #
  # same elements size case
  #   alpha = ['a','b','c', nil,'d']
  #   numbers = [1, 2, nil, 3]
  #   lists = [alpha, numbers]
  #   ret = lists.together_compact!
  #   print lists # => output [['a','b','c','d'], [1, 2, 3]]
  #   print ret # => output [['a','b','c','d'], [1, 2, 3]]
  def together_compact!
    if_not_contain_array_rails_type_error
    each { |list|list.compact! }
  end

  alias_method :tcompact, :together_compact
  alias_method :tcompact!, :together_compact!
end

Version data entries

114 entries across 114 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.150 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.149 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.148 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.147 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.146 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.145 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.144 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.143 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.142 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.141 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.140 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.139 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.138 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.137 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.136 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.135 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.134 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.133 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.132 lib/open_classes/array/together_compact.rb
tbpgr_utils-0.0.131 lib/open_classes/array/together_compact.rb