Sha256: cd7eaf215a62933c8856f1d162b924d2dacc8e7f2bc6806cdd1d399a17bb61d9

Contents?: true

Size: 1.08 KB

Versions: 115

Compression:

Stored size: 1.08 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 shift.
  #
  # together_shift has alias :tshift
  #
  # not empty case
  #   lists = [[1, 2], [5, 6]]
  #   ret = lists.together_shift
  #   print ret # => [1, 5]
  #   print lists # => [2, 6]
  #
  # empty case
  #   lists = [[], []]
  #   ret = lists.together_shift
  #   print ret # => [nil, nil]
  #   print lists # => [[], []]
  #
  # not empty case with args
  #   lists = [[1, 2], [5, 6]]
  #   ret = lists.together_shift 2
  #   print ret # => [[1, 2], [5, 6]]
  #   print lists # => [[], []]
  #
  # not empty case with args
  #   lists = [[], []]
  #   ret = lists.together_shift 2
  #   print ret # => [[], []]
  #   print lists # => [[], []]
  def together_shift(count = nil)
    if_not_contain_array_rails_type_error
    if count.nil?
      reduce([]) { |ret, list|ret << list.shift }
    else
      reduce([]) { |ret, list|ret << list.shift(count) }
    end
  end

  alias_method :tshift, :together_shift
end

Version data entries

115 entries across 115 versions & 1 rubygems

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