Hello. My name is Piotr S. and Iâ€™m new to the list (and to

JRuby). Apologies if the below is a known issue or a FAQ; I tried

googling and searching through the listâ€™s archive, but to no avail.

Now, my problem â€“ a discrepancy in break handling between JRuby 1.1.1

and MRI 1.8.6.p114. After defining the below new Enumerable iterators:

module Enumerable

def every_pair_with_indices

each_with_index do |a, i|

each_with_index do |b, j|

yield [a, b, i, j] if i < j

end

end

end

def every_pair

every_pair_with_indices do |a, b, i, j|

yield [a, b]

end

end

end

JRuby and MRI give me different results:

ruby 1.8.6 (2008-03-03 patchlevel 114) [i686-linux]

[:a,:b,:c,:d].every_pair{|a,b| p [a,b]; break if [a,b] == [:a,:c]}

[:a, :b]

[:a, :c]

=> nil

ruby 1.8.6 (2008-04-22 rev 6555) [i386-jruby1.1.1]

[:a,:b,:c,:d].every_pair{|a,b| p [a,b]; break if [a,b] == [:a,:c]}

[:a, :b]

[:a, :c]

[:b, :c]

[:b, :d]

[:c, :d]

=> [:a, :b, :c, :d]

If I understand the things right, in JRuby the break only breaks

the innermost every_pair loop (i.e., it â€˜unwindsâ€™ it into two loops,

and breaks the inner one), while in MRI break actually breaks out of

every_pair.

Is this a known discrepancy, and if so, is there either a way to make

JRuby behave like MRI or a way to rewrite every_pair so itâ€™s possible

to break out of it (in the same manner like out of Enumerable#each)?

– Shot