Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Allows for iteration of multiple enumerables
Gem::Specification.new do |s|
s.name = 'enumerable_collate'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'Hugo Peixoto'
s.email = 'hugo.peixoto@gmail.com'
s.summary = 'Enumerable Collate'
s.description = 'Allows for iteration of multiple enumerables'
s.files = ['enumerable_collate.rb']
s.require_path = '.'
s.add_development_dependency('rspec', ["~> 2.0"])
end
module Enumerable
def collate *other, &block
([self] + other).each { |enum| enum.each &block }
end
end
$:.unshift(File.dirname(File.absolute_path(__FILE__)))
require 'enumerable_collate'
describe Enumerable do
it "can collate no enumerables" do
([1,2,3].collate.collect{|i| i}).should eq([[1,2,3]])
end
it "can collate one enumerables" do
([1,2,3].collate([4,5]).collect{|i| i}).should eq([[1,2,3],[4,5]])
end
it "can collate various enumerables" do
([1,2,3].collate([4,5],[6,7]).collect{|i| i}).should eq([[1,2,3],[4,5],[6,7]])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment