-
-
Save pkoch/2864674 to your computer and use it in GitHub Desktop.
Allows for iteration of multiple enumerables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = '[email protected]' | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Enumerable | |
def collate *other, &block | |
([self] + other).each { |enum| enum.each &block } | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.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