Sha256: 6536e93a63085c4dab05fb0fb80e72cd79651d3c1f695d7b7ae0462e62c6d288

Contents?: true

Size: 1013 Bytes

Versions: 115

Compression:

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

  alias_method :tlast, :together_last
end

Version data entries

115 entries across 115 versions & 1 rubygems

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