custom Hash.to_yaml fails with a Hash inside an Array value
-----------------------------------------------------------

                 Key: JRUBY-3422
                 URL: http://jira.codehaus.org/browse/JRUBY-3422
             Project: JRuby
          Issue Type: Bug
    Affects Versions: JRuby 1.1.6
         Environment: jruby 1.1.6 (ruby 1.8.6 patchlevel 114) (2008-12-17 rev 
8388) [i386-java]
            Reporter: Karol Bucek
            Assignee: Thomas E Enebo


this seems as an YAML::Emiter MRI incompatibility

let's suppose that we have redefined Hash.to_yaml :

{code} 
require 'yaml'

Hash.class_eval do

  def to_yaml( opts = {} )
    YAML::quick_emit( self, opts ) do |out|
      out.map( taguri, to_yaml_style ) do |map|
        each do |k, v|
          map.add( k, v )
        end
      end
    end
  end

end
{code}

now the following Hash structure will fail to convert to YAML :

{code}
hash = { "element" => "value", "array" => [ { "nested_element" => 
"nested_value" } ] }
puts hash.to_yaml # works only with C-Ruby
{code}

with a TypeError :

{code}
yaml:210:in `to_yaml_node': wrong argument type String (expected 
YAML::JvYAML::Node) (TypeError)
        from yaml:142:in `to_s'
        from yaml:114:in `map'
        from main.rb:22:in `to_yaml'
        from yaml:64:in `call'
        from yaml:64:in `emit'
        from yaml:100:in `quick_emit'
        from main.rb:21:in `to_yaml'
        from main.rb:38
{code}

the problem seems to be related to the array value with a hash element

the provided Hash.to_yaml code is for demonstration only and is actualy the 
same as the one available in C-Ruby, overriding the to_yaml method makes sense 
e.g. when someone wants the keys to be sorted in the yaml output.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to