#!/usr/bin/env ruby # encoding: utf-8 require 'tempfile' require 'yaml' #YAML::ENGINE.yamler = "syck" YAML::ENGINE.yamler = "psych" module Psych module Visitors class YAMLTree < Psych::Visitors::Visitor def binary? string false end private :binary? end end end class Bar def initialize #@bar = "bär" @bar = "bär".force_encoding('ascii-8bit') end def encode_with(coder=nil) ["@bar"].each do |a| coder[a[1..-1]] = instance_variable_get(a) end coder.tag = ['!ruby/Test', self.class.name].join(':') end end class Foo def initialize #@foo = "föö" @foo = "föö".force_encoding('ascii-8bit') @bar = Bar.new @baz = "nää" end def encode_with(coder=nil) ["@foo", "@bar"].each do |a| coder[a[1..-1]] = instance_variable_get(a) end coder.tag = ['!ruby/Test', self.class.name].join(':') end end test = ["Grüße", "Öl", "Käse", Foo.new] ### # == Output test via Tempfile # #Tempfile.open('test', './') do |fh| # YAML.dump(test, fh) # fh.close # FileUtils.mv(fh.path, 'result') # FileUtils.chmod(0644, 'result') #end puts test.to_yaml