Forum: JRuby Upper case global variable?

Posted by Budyanto Himawan (ngambek2003)
on 2010-03-05 18:42
Is there a restriction when naming global variables to be shared between
java and jruby?

I'm using the jsr223 way and if I do

engine.put("Logger", logger), from jruby, $Logger is nil.
            -
          Begins with Upper case

If I use

engine.put("logger", logger), from jruby, $logger is not nil.

In reading the ruby documentation, it seems that global variables can
have uppercase names.
Posted by Budyanto Himawan (ngambek2003)
on 2010-03-05 18:43
Budyanto Himawan wrote:
> Is there a restriction when naming global variables to be shared between
> java and jruby?
> 
> I'm using the jsr223 way and if I do
> 
> engine.put("Logger", logger), from jruby, $Logger is nil.
>             -
>           Begins with Upper case
> 
> If I use
> 
> engine.put("logger", logger), from jruby, $logger is not nil.
> 
> In reading the ruby documentation, it seems that global variables can
> have uppercase names.

I'm using jruby 1.4
Posted by Yoko Harada (Guest)
on 2010-03-05 19:49
(Received via mailing list)
On Fri, Mar 5, 2010 at 12:42 PM, Budyanto Himawan <lists@ruby-forum.com> 
wrote:
>
> engine.put("logger", logger), from jruby, $logger is not nil.
>
> In reading the ruby documentation, it seems that global variables can
> have uppercase names.

Would you please use JRuby 1.5.0.dev, whose snapshots are at
http://ci.jruby.org/snapshots/? There should not be any limitation for
global var names, but in JRuby 1.4.0, regex to judge Ruby variable
names wasn't correct. If you want to stay on JRuby 1.4.0, choosing
transient local variable behavior, see
http://kenai.com/projects/jruby/page/RedBridge#Local_Variable_Behavior_Options,
would work. In this case, global variables have a name start with "$"
even in Java, so you need to rewrite:

 engine.put("$Logger", logger);

-Yoko

> --
> Posted via http://www.ruby-forum.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
Posted by Budyanto Himawan (ngambek2003)
on 2010-03-06 00:16
Thanks..yah the 1.5 seems to work better.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.