public
Created

  • Download Gist
test.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#!/usr/bin/env ruby
 
class FooBar
include Enumerable
def initialize( array1 , array2 )
@array_out = Array.new
if array1 != [] and array2 != []
for i in array1
for j in array2
k = [i,j].join("|")
@array_out.push( k )
end
end
end
end
def each
current_index = 0
while current_index < @array_out.size
yield @array_out[current_index]
current_index += 1
end
end
end
 
class Array
def reverse_iterate
current_index = self.size-1
while current_index >= 0
yield self[current_index]
current_index -= 1
end
end
end
 
#[2,4,5,6,9].reverse_iterate { |i| puts i.inspect }
 
x = FooBar.new( (1..3) , [4,6] )
x.each{ |i| puts i.inspect }
 
y = FooBar.new( [ 'A' , 'B' , 'a' , 'b' ] , [4,6] )
y.each{ |i| puts i.inspect }

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.