Sha256: 9a291a59695490b86330ba58d84bd2ad011638e7be363ce33c88e37a0b8880a8

Contents?: true

Size: 643 Bytes

Versions: 6

Compression:

Stored size: 643 Bytes

Contents

# encoding: utf-8

# Array
class Array
  # Arrays loop together
  #
  #   alpha = %w{one two three}
  #   numbers = %w{1 2 3}
  #   [alpha, numbers].together do |first, second|
  #     print "#{first}:#{second}\n"  # => output one:1, two:2, three:3
  #   end
  def together
    each { |f|fail TypeError, "you have to use [Array1, Array2, ...] | #{f.class} is invalid" unless f.class == Array }
    first.each_with_index do |i_v, i|
      eval_each = []
      each_with_index do |j_v, j|
        eval_each << "self[#{j}][#{i}]"
      end
      eval_each_str = eval_each.join(',')
      instance_eval "yield(#{eval_each_str})"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.12 lib/open_classes/array.rb
tbpgr_utils-0.0.11 lib/open_classes/array.rb
tbpgr_utils-0.0.10 lib/open_classes/array.rb
tbpgr_utils-0.0.9 lib/open_classes/array.rb
tbpgr_utils-0.0.8 lib/open_classes/array.rb
tbpgr_utils-0.0.7 lib/open_classes/array.rb