Re: de-camelcase a filename




Veterans can provide more succinct ways though :)

I wouldn't consider myself a veteran yet, but here's how Rails does it:

camel_cased_word.to_s.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase

That also changes :: to /, so it's handy for translating a module name to a file path. It's not exactly more succinct, but you can cut it down as you see fit.

Brett


.