In Chapter 5 of his book, Flexible Rails, Peter Armstrong''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!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---