Created
May 19, 2010 16:00
-
-
Save bhuga/406468 to your computer and use it in GitHub Desktop.
JRuby enumerator bug
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
# Demonstrates a JRuby difference with RDF enumerators | |
require 'rdf' | |
require 'rdf/ntriples' | |
include RDF | |
s = Statement.new(FOAF.age, FOAF.age, FOAF.age) | |
r = Repository.new | |
r.insert(s) | |
r.enum_triple.each do |*triple| puts triple.count end #MRI: 1, JRuby: 3 | |
r.enum_triple.any? do |*triple| puts triple.count end #MRI: 1, JRuby: 1 | |
# Without RDF, demonstrating the bug more cleanly: | |
include Enumerable | |
a = [1,2] | |
def each_smashed(array, &block) | |
block.call( *array ) | |
end | |
Enumerator.new(self, :each_smashed, a).each do |*smashed| puts smashed.count end | |
# MRI: 1, JRuby: 2, 1.9: 2 | |
Enumerator.new(self, :each_smashed, a).any? do |*smashed| puts smashed.count end | |
# MRI: 1, JRuby: 1, 1.9: 2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment