Created
July 25, 2015 19:16
-
-
Save rtyler/7d9fd30a7093c7cd362b to your computer and use it in GitHub Desktop.
Fun with Nashorn and JRuby
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
➜ ~ pry | |
[1] pry(main)> require 'java' | |
=> false | |
[2] pry(main)> puts RUBY_PLATFORM; puts RUBY_VERSION | |
java | |
1.9.3 | |
=> nil | |
[3] pry(main)> java_import 'javax.script.ScriptEngineManager' | |
=> [Java::JavaxScript::ScriptEngineManager] | |
[4] pry(main)> engine = ScriptEngineManager.new.get_engine_by_name('nashorn') | |
=> #<Java::JdkNashornApiScripting::NashornScriptEngine:0x2fb3536e> | |
[5] pry(main)> bindings = engine.create_bindings | |
=> {} | |
[6] pry(main)> engine.eval("print(2 + '2');", bindings) | |
22 | |
=> nil | |
[7] pry(main)> rc = engine.eval("2 + '2'", bindings) | |
=> "22" | |
[8] pry(main)> rc | |
=> "22" | |
[9] pry(main)> rc.class | |
=> String | |
[10] pry(main)> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment