我想在 Ruby 应用程序中运行 jQuery 并使用它来操作 HTML 字符串。(是的,我知道还有其他 Ruby 库可以处理该任务,但在这种情况下我有充分的理由使用 jQuery。)这可能吗?我知道我可以使用 ExecJS 在我的 Ruby 应用程序中执行简单的 JavaScript 代码,但 jQuery 似乎不起作用:
irb(main):001:0> require 'execjs'
=> true
irb(main):002:0> require 'open-uri'
=> true
irb(main):003:0> context = ExecJS.compile(open("http://code.jquery.com/jquery-1.9.1.js").read)
=> <Return omitted for brevity>
irb(main):004:0> context.call("$", "<div>Test</div>")
ExecJS::ProgramError: ReferenceError: window is not defined
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:68:in `extract_result'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:28:in `block in exec'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-.4.0/lib/execjs/external_runtime.rb:41:in `compile_to_tempfile'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-.4.0/lib/execjs/external_runtime.rb:27:in `exec'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-.4.0/lib/execjs/external_runtime.rb:19:in `eval'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-.4.0/lib/execjs/external_runtime.rb:33:in `call'
from (irb):4
from c:/RailsInstaller/Ruby1.9.3/bin/irb:12:in `<main>'
我怎样才能让它工作?