|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
jruby 1.4 CLI vs. embedded syntax difference?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 not 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) |
|
|
Re: jruby 1.4 CLI vs. embedded syntax difference?On Fri, Nov 6, 2009 at 10:07 PM, ed_s <ed_sumitra@...> wrote:
> > 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 not > work in the embedded environment? From the exception, I guess you created a java.lang.Map type object and called Ruby method with that object in its argument. Right? This is a Java integration related problem. I think this seems to be a bug since Map type object didn't converted to Ruby's Hash. In the method, getMaxList, the Java's Map type object was there as a "hash." Because Java's Map and its descendants don't have "each" method, you got the error. Would you file this? -Yoko > > 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) > -- > View this message in context: http://old.nabble.com/jruby-1.4-CLI-vs.-embedded-syntax-difference--tp26235462p26235462.html > Sent from the JRuby - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: jruby 1.4 CLI vs. embedded syntax difference?Yoko,
You are correct. I instantiate a Map object in Java and pass it as an argument to the ruby function. I will go ahead and file an issue. Thanks, Ed
|
| Free embeddable forum powered by Nabble | Forum Help |