How to best change the default value of dasherize (using Edg

Hi all,

I’m trying to turn off dasherize in all cases, since converting
underscores to hyphens breaks the way that I want to handle XML (with
E4X in Flex 2).

I’ve read the other threads about dasherize on this list. I’m on Edge
Rails, so I can successfully turn off dasherize for a single usage
with something like

render :xml => @task.to_xml(:dasherize => false)

I don’t want to have to do this in every case, of course. So, I can
go ahead and add the following to my application.rb:

module ActiveRecord #:nodoc:
module XmlSerialization
#We change the default for :dasherize, since it is never what we
want.
def to_xml(options = {:dasherize => false})
XmlSerializer.new(self, options).to_s
end
end
…etc…
end

This works fine.

However, I also have to change the behaviour for two of the other
to_xml methods:

to_xml (ActiveSupport::CoreExtensions::hash::Conversions)
to_xml (ActiveSupport::CoreExtensions::Array::Conversions)

(The to_xml in ActiveRecord::Errors doesn’t use it.)

Anyway, the source in the Hash::Conversions and Array::Conversions is
larger, so I don’t want to override the method just to change the
default. Is there any way that I can set the default of :dasherize to
false without doing that?

[I asked about this when I was on Rails 1.1 and the response was to just add to_xml_nodash methods or modify the to_xml ones, which worked but was unfortunate since by overriding the methods I’d clobber any changes to them. I’m just wondering if anyone who is a Ruby / Rails guru can think of a better way to do this now that there is actually the :dasherize option to play with…]

I wish there was some constant I could just set to make dasherize
default to false in all three methods that use it. I’m sure I’m not
the only one…

Thanks,
Peter A.


Peter A.
http://www.flexiblerails.com – Flex 2 and Rails 1.1 or 1.2 together!
(PDF-only book)