java map objects not working correctly with embedded jruby
----------------------------------------------------------
Key: JRUBY-4223
URL: http://jira.codehaus.org/browse/JRUBY-4223
Project: JRuby
Issue Type: Bug
Components: Embedding
Affects Versions: JRuby 1.4
Environment: windows xp, tomcat 6, jruby 1.4, bsf api 3.0
Reporter: Ed S
Attachments: samplecode.rar
code below works with JRuby CLI but not in embedded JRuby
MyHash = {"1" => "One", "2" => "Two", "3" => "Three", "4" => "Four"}
def getMaxList(hash,num)
(num < hash.size) ? hash.values[0..num-1] : hash.values
end
puts getMaxList(MyHash,2).inspect
need to use the alternate form instead
def getMaxList(hash,num)
result = []
for i in 0..num-1
result << hash[i.to_s]
end
result
end
The error I get with the first form of the code is
<script>:6:in `getMaxList': undefined method `[]' for
#<#<Class:01x12e5c94>:0xbffc3a> (NoMethodError)
from <script>:4:in `each'
from <script>:4:in `getMaxList'
from :1
org.jruby.embed.InvokeFailedException: undefined method `[]' for
#<#<Class:01x12e5c94>:0xbffc3a>
at
org.jruby.embed.internal.EmbedRubyObjectAdapterImpl.call(EmbedRubyObjectAdapterImpl.java:369)
at
org.jruby.embed.internal.EmbedRubyObjectAdapterImpl.callMethod(EmbedRubyObjectAdapterImpl.java:188)
at
org.jruby.embed.ScriptingContainer.callMethod(ScriptingContainer.java:585)
at
org.jruby.embed.jsr223.JRubyEngine.invokeFunction(JRubyEngine.java:278)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.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