# Overriding to\_xml() - Why Does This Work?

**URL:** <https://www.ruby-forum.com/t/overriding-to-xml-why-does-this-work/135494>\
**Category:** Rails\
**Created:** [April 22, 2008, 5:57pm UTC](https://www.ruby-forum.com/t/overriding-to-xml-why-does-this-work/135494 "2008-04-22T17:57:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbnbnb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a87d85/32.png) [@nbnbnb](https://www.ruby-forum.com/u/nbnbnb)\
**Post date:** [April 22, 2008, 5:57pm UTC](https://www.ruby-forum.com/t/overriding-to-xml-why-does-this-work/135494/1 "2008-04-22T17:57:29Z")

</div>

In Chapter 5 of his book, Flexible Rails, Peter A.'s leads his  
readers through an exercise to override the behavior of to\_xml() in  
ActiveRecord objects so that :dasherize would be false by default. I  
found his solution inelegant. I came up with a more elegant one, and  
it seems to work.

All I did was add the following to the very end of myapp/config/  
environment.rb:

class ActiveRecord::Base  
def to\_xml(options=nil, &block)  
super options == nil ? { :dasherize =\> false } :  
options.merge(:dasherize =\> false), &block  
end  
end

But, I don’t know why it works. Specifically, how come I can invoke  
“super” even though I am not subclassing ActiveRecord::Base, and  
ActiveRecord::Base’s parent class (whom I believe is Object) doesn’t  
implement to\_xml()?

Can someone who is more enlightened about Ruby/Rails help me out?

Thanks!
