如何使用 Syck 在 1.9 中的 JRuby 中执行 YAML?

发布于 2024-11-05 21:08:27 字数 1419 浏览 0 评论 0原文

如果我在 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,因为我在 如何反序列化 Psych 中的类?

If I run JRuby in Ruby 1.9 mode, and tell it to use Syck rather than Psych, nothing seems to work. Am I missing something?

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)'

Background: I'm trying to use Syck because of my problems with Psych in How do I deserialize classes in Psych?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟沫凡尘 2024-11-12 21:08:27

看起来它没有在 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 的发行说明表示与 Ruby 1.9.2 的兼容性达到了非常高的水平。 也许这并没有延伸到syck..?

Looks like it's not implemented in JRuby. Under 1.9.2:

ruby-1.9.2-p180 :001 > require 'YAML'
 => true 
ruby-1.9.2-p180 :002 > require 'YAML/syck'
 => true 

Under 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)'

Although I'm not (yet) an expert with JRuby, the release notes for JRuby 1.6.0 say compatibility with Ruby 1.9.2 to a very high level. Perhaps this doesn't extend to syck..?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文