Sha256: 88afef3ca950729c73a6b2bfba5c80e31c96f1bb89bbffb2b0915c2eaea84697

Contents?: true

Size: 1023 Bytes

Versions: 115

Compression:

Stored size: 1023 Bytes

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 first.
  #
  # together_first has alias :tfirst
  #
  # no args case
  #   lists = [[*1..5], [*6..10]]
  #   ret = lists.together_first
  #   print ret # => [1, 6]
  #
  # has args 2 case
  #   lists = [[*1..5], [*6..10]]
  #   ret = lists.together_first 2
  #   print ret # => [[1, 2], [6, 7]]
  #
  # has args 0 case
  #   lists = [[*1..5], [*6..10]]
  #   ret = lists.together_first 0
  #   print ret # => [[], []]
  #
  # has args over size case
  #   lists = [[*1..5], [*6..10]]
  #   ret = lists.together_first 6
  #   print ret # => [[*1..5], [*6..10]]
  def together_first(index = nil)
    if_not_contain_array_rails_type_error
    each_return = index == 0 ? '[]' : index.nil? ? 'list.first' : 'list.first(index)'
    reduce([]) { |ret, list|ret << eval(each_return, binding) }
  end

  alias_method :tfirst, :together_first
end

Version data entries

115 entries across 115 versions & 1 rubygems

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