Skip to content

Instantly share code, notes, and snippets.

@byteit101
Created November 23, 2014 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byteit101/701603c8434fdb01f243 to your computer and use it in GitHub Desktop.
Save byteit101/701603c8434fdb01f243 to your computer and use it in GitHub Desktop.
bindings steal globals
# using IRB jruby-1.7.16
sem = Java.javax.script.ScriptEngineManager.new
# => #<Java::JavaxScript::ScriptEngineManager:0x5bb21b69>
$FOO
# => nil
$FOO = "1"
# => "1"
jr = sem.getEngineByName("jruby")
# => #<Java::OrgJrubyEmbedJsr223::JRubyEngine:0x7ce6a65d>
jr.eval("$FOO")
# => "1"
$FOO
# => nil #What? it stole the global!
$FOO = "2"
# => "2"
jr.eval("$FOO")
# => "1"
jr.setBindings(sem.getBindings, javax.script.ScriptContext.ENGINE_SCOPE)
# => nil
jr.eval("$FOO")
# => "1"
$FOO
# => nil # What? It reset the global!
$FOO = "3"
# => "3"
$FOO
# => "3"
jr.eval("$FOO")
# => "1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment