Sha256: 210738f24caac52dcfed3dbed67ecf615acc3b59f5d8a8f7f3aeecf60b9a679e
Contents?: true
Size: 698 Bytes
Versions: 26
Compression:
Stored size: 698 Bytes
Contents
module Enumerable # Iterators ovr each element pairing. # # [:a,:b,:c,:d].each_pair { |a,b| puts "#{a} -> #{b}" } # # _produces_ # # a -> b # c -> d # def each_pair #:yield: e1 = nil each_with_index do |e,i| if i % 2 == 0 e1 = e next else yield(e1,e) end end end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCEnumerable < Test::Unit::TestCase def test_each_pair r = [] a = [1,2,3,4] a.each_pair{ |a,b| r << [a,b] } assert_equal( [[1,2],[3,4]], r ) end end =end
Version data entries
26 entries across 26 versions & 1 rubygems