如果我在Ruby 1.9模式下运行JRuby,并告诉它使用Syck而不是Psych,那么似乎没有任何效果。我错过了什么吗?
Andrew-Grimms-MacBook-Pro:~ agrimm$ ruby --version
jruby 1.6.1 (ruby-1.8.7-p330) (2011-05-08 3fe11da) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_24) [darwin-x86_64-java]
Andrew-Grimms-MacBook-Pro:~ agrimm$ ruby --1.9 -S irb
jruby-head :001 > require "yaml"
=> true
jruby-head :002 > YAML::ENGINE.yamler = "syck"
=> "syck"
jruby-head :003 > YAML::ENGINE.yamler
=> "syck"
jruby-head :004 > 42.to_yaml
NameError: uninitialized constant Syck::Yecht
from org/jruby/RubyModule.java:2569:in `const_missing'
from org/jruby/RubyClass.java:218:in `allocate'
from /Users/agrimm/.rvm/rubies/jruby-head/lib/ruby/1.9/syck.rb:102:in `emitter'
from /Users/agrimm/.rvm/rubies/jruby-head/lib/ruby/1.9/syck.rb:399:in `quick_emit'
from /Users/agrimm/.rvm/rubies/jruby-head/lib/ruby/1.9/syck/rubytypes.rb:371:in `to_yaml'
from (irb):4:in `evaluate'
from org/jruby/RubyKernel.java:1093:in `eval'
from org/jruby/RubyKernel.java:1418:in `loop'
from org/jruby/RubyKernel.java:1205:in `catch'
from org/jruby/RubyKernel.java:1205:in `catch'
from /Users/agrimm/.rvm/rubies/jruby-head/bin/jirb:17:in `(root)'
背景:我正在尝试使用Syck,因为我在How do I deserialize classes in Psych?
中遇到了与Psych有关的问题答案 0 :(得分:1)
看起来它没有在JRuby中实现。根据1.9.2:
ruby-1.9.2-p180 :001 > require 'YAML'
=> true
ruby-1.9.2-p180 :002 > require 'YAML/syck'
=> true
在JRuby 1.6.2下
jruby-1.6.2 :001 > require 'YAML'
=> true
jruby-1.6.2 :002 > require 'YAML/syck'
LoadError: no such file to load -- YAML/syck
from org/jruby/RubyKernel.java:1038:in `require'
from (irb):2:in `evaluate'
from org/jruby/RubyKernel.java:1088:in `eval'
from /Users/matt/.rvm/rubies/jruby-1.6.2/lib/ruby/1.8/irb.rb:158:in `eval_input'
from /Users/matt/.rvm/rubies/jruby-1.6.2/lib/ruby/1.8/irb.rb:271:in `signal_status'
from /Users/matt/.rvm/rubies/jruby-1.6.2/lib/ruby/1.8/irb.rb:155:in `eval_input'
from org/jruby/RubyKernel.java:1419:in `loop'
from org/jruby/RubyKernel.java:1191:in `catch'
from /Users/matt/.rvm/rubies/jruby-1.6.2/lib/ruby/1.8/irb.rb:154:in `eval_input'
from /Users/matt/.rvm/rubies/jruby-1.6.2/lib/ruby/1.8/irb.rb:71:in `start'
from org/jruby/RubyKernel.java:1191:in `catch'
from /Users/matt/.rvm/rubies/jruby-1.6.2/lib/ruby/1.8/irb.rb:70:in `start'
from /Users/matt/.rvm/rubies/jruby-1.6.2/bin/irb:17:in `(root)'
虽然我还不是JRuby的专家,但是JRuby 1.6.0的发行说明说compatibility with Ruby 1.9.2 to a very high level.
也许这不会扩展到syck ..?