How do I do YAML in JRuby in 1.9 with Syck?

1.7k Views Asked by At

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?

1

There are 1 best solutions below

0
On

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..?