Created
November 23, 2014 23:04
-
-
Save byteit101/701603c8434fdb01f243 to your computer and use it in GitHub Desktop.
bindings steal globals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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