# Inconsistent Hash#to\_xml Method

**URL:** <https://www.ruby-forum.com/t/inconsistent-hash-to-xml-method/183312>\
**Category:** Rails\
**Created:** [February 11, 2010, 3:44pm UTC](https://www.ruby-forum.com/t/inconsistent-hash-to-xml-method/183312 "2010-02-11T15:44:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 11, 2010, 3:44pm UTC](https://www.ruby-forum.com/t/inconsistent-hash-to-xml-method/183312/1 "2010-02-11T15:44:52Z")

</div>

I have a unit test that demonstrates some inconsistent behavior with a  
Hash being converted to XML with the :root option. Sometimes it works  
fine:

Hash.new.to\_xml(:root =\> ‘test’)  
“\<?xml version=\"1.0\" encoding=\"UTF-8\"?\>\n\n\n”

But sometimes I get an argument error:

Hash.new.to\_xml(:root =\> ‘test’)  
ArgumentError Exception: wrong number of arguments (1 for 0)

I thought it may be a bug related to the version of Rails, but I have  
tried several versions and have the same problem. Anyone have any  
ideas of where I should be looking?

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 11, 2010, 4:25pm UTC](https://www.ruby-forum.com/t/inconsistent-hash-to-xml-method/183312/2 "2010-02-11T16:25:15Z")

</div>

On 11 Feb 2010, at 15:43, TomRossi7 wrote:

> ArgumentError Exception: wrong number of arguments (1 for 0)
> 
> I thought it may be a bug related to the version of Rails, but I have  
> tried several versions and have the same problem. Anyone have any  
> ideas of where I should be looking?

Sounds to me you are including some other class that has the to\_xml  
method somewhere. It can be either something an outdated plugin uses  
or some code in your lib/ folder or part of a gem. That’s why it only  
happens “sometimes”, it only happens in classes that have the non-  
Rails to\_xml method loaded.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 11, 2010, 4:27pm UTC](https://www.ruby-forum.com/t/inconsistent-hash-to-xml-method/183312/3 "2010-02-11T16:27:35Z")

</div>

Yep! I found an old plugin that was actually overwriting the  
Hash#to\_xml method! Thanks!

–Tom
