This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Enumerate Side-by-side with SyncEnumerator
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
The each iterates through both collections simultaneously. You can pass any number of collections into SyncEnumerator. And, naturally, you can use any of the normal set of Enumerable methods. And you will.
require 'generator'
class Sync < SyncEnumerator
def self.[]( *args ); new( *args ); end
end
Sync[numbers,letters].map { |n,l| "#{n} #{l}" }.join "\n"