Sha256: bdf1476f9c1574a193c52c530de0817a68da36195bf6ec46669f6ea8bb3b7e32

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 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(&:compact!)
  end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.151 lib/open_classes/array/together_compact.rb