From: "Ara.T.Howard" Date: 2005-05-12T02:25:27+09:00 Subject: defining a custom to_yaml method to inline hashes check out the following: jib:~ > cat a.rb require 'yaml' # yaml can load inline hashes inline_hash = YAML::load "--- { jid: 121, metric: started, time: 2005-05-10 08:18:22.523016 }" puts '=' * 8 y inline_hash puts # attempt to bludgeon to object into emitting in an inline fashion class << inline_hash def to_yaml(*a, &b) '{ ' << map{|kv| kv.join(': ')}.join(', ') << ' }' end end # looks good at first puts '=' * 8 y inline_hash puts # but doesn't really work after all when part of another object puts '=' * 8 y({'running' => inline_hash}) puts jib:~ > ruby a.rb ======== --- time: 2005-05-10 08:18:22.523016 jid: 121 metric: started ======== { time: 2005-05-10 08:18:22.523016, jid: 121, metric: started } ======== --- running: notice the second block is alright but the third is not. i know i need to do something like def to_yaml(*a, &b) YAML::quick_emit(*a, &b) do |out| # now what? end end but can't seem to find anything in the docs or samples. cheers. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | renunciation is not getting rid of the things of this world, but accepting | that they pass away. --aitken roshi ===============================================================================