TRANS wrote:
> On 3/23/07, David Vanderson <dvanderson / customink.com> wrote:
>> Hello,
>>
>> I've been having some trouble converting rexml documents to yaml and
>> back.  See the following test case:
>> #!/usr/bin/env ruby
>> require 'yaml'
>> require 'rexml/document'
>> d = REXML::Document.new '<my_doc my_attr="my_val">Hello</my_doc>'
>> puts YAML::load(d.to_yaml)
>>
>> When I run it I get this error:
>> NoMethodError: undefined method `each_value' for "my_val":String
>>         from /usr/lib/ruby/1.8/rexml/element.rb:1029:in `each_attribute'
>>         from /usr/lib/ruby/1.8/rexml/element.rb:1025:in `each_attribute'
>>         from /usr/lib/ruby/1.8/rexml/element.rb:684:in `write'
>>         from /usr/lib/ruby/1.8/rexml/document.rb:165:in `write'
>>         from /usr/lib/ruby/1.8/rexml/document.rb:163:in `write'
>>         from /usr/lib/ruby/1.8/rexml/node.rb:23:in `to_s'
>>         from (irb):5
>>
>> I believe it has something to do with the REXML::Attributes class
>> extending Hash, so YAML::load produces just a Hash, without Attribute
>> objects inside.
>>
>> This is with:
>> ruby 1.8.4 (2005-12-24) [i386-linux]
>>
>> Can anyone else reproduce this?
> 
> Get the same. Same version of ruby, though.
> 
> T.

Ditto for 1.8.5

$ ruby -v
ruby 1.8.5 (2006-08-25) [i686-darwin8.8.3]

$ ruby ruby_xml_yaml.rb
/usr/local/lib/ruby/1.8/rexml/element.rb:1028:in `each_attribute': 
undefined method `each_value' for "my_val":String (NoMethodError)
         from /usr/local/lib/ruby/1.8/rexml/element.rb:1024:in `each_value'
         from /usr/local/lib/ruby/1.8/rexml/element.rb:1024:in 
`each_attribute'
         from /usr/local/lib/ruby/1.8/rexml/element.rb:683:in `write'
         from /usr/local/lib/ruby/1.8/rexml/document.rb:177:in `write'
         from /usr/local/lib/ruby/1.8/rexml/document.rb:175:in `each'
         from /usr/local/lib/ruby/1.8/rexml/document.rb:175:in `write'
         from /usr/local/lib/ruby/1.8/rexml/node.rb:23:in `to_s'
         from ruby_xml_yaml.rb:5:in `puts'
         from ruby_xml_yaml.rb:5