Skip to content

Instantly share code, notes, and snippets.

@bhuga
Created May 19, 2010 16:00
Show Gist options
  • Save bhuga/406468 to your computer and use it in GitHub Desktop.
Save bhuga/406468 to your computer and use it in GitHub Desktop.
JRuby enumerator bug
# 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