jruby 1.4 CLI vs. embedded syntax difference?

2 messages Options
Embed this post
Permalink
ed s

jruby 1.4 CLI vs. embedded syntax difference?

Reply Threaded More More options
Print post
Permalink
I have a JRuby script that works fine through the JRuby command line. However when I execute the same script in an embedded environment, Tomcat/bsf/jruby, I get undefined method errors. Any pointers as to why the script does nto work in the embedded environment?

Thanks,
Ed

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 below 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)
Hugo <Nabble>

Re: jruby 1.4 CLI vs. embedded syntax difference?

Reply Threaded More More options
Print post
Permalink
Sorry, but this forum is for Nabble Support only.