WPC created JRUBY-6381:
--------------------------
Summary: java.util.Collection#each dose not respect to_ary defined
by objects that are iteratered
Key: JRUBY-6381
URL: https://jira.codehaus.org/browse/JRUBY-6381
Project: JRuby
Issue Type: Bug
Components: Java Integration
Affects Versions: JRuby 1.6.5
Environment: Mac OSX 10.7.2, Java 1.6.0_29 64bit
Reporter: WPC
If you have a collection of objects that defined to_ary method, with normal
ruby array you get sort of argument pattern matching when you iterate them:
class Pair
def initialize(a, b)
@a = a
@b = b
end
def to_ary
[@a, @b]
end
end
>> [Pair.new('first', 'second')].each {|a, b| p a; p b}
"first"
"second"
But with a java collection you do not get this behavior
java.util.ArrayList.new([Pair.new('first', 'second')]).each { |a, b| p a; p b
}
#<Pair:0x54be8c3e @b="second", @a="first">
nil
This seems like only a little bit inconsistency. But it do give me
inconvenience currently. I have java methods returns a List of Pair defines in
java which has to_ary defined on them. I need call to_a on the list each time I
want to map through it.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email