Re: de-camelcase a filename
- From: Brett Simmers <bsimmers@xxxxxxx>
- Date: Sun, 1 Jul 2007 03:33:24 +0900
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
.
- Prev by Date: Re: [QUIZ] LSRC Name Picker (#129)
- Next by Date: Re: Ruby vs Java (this,self/main)
- Previous by thread: Tk TopLevel window
- Next by thread: Re: de-camelcase a filename
- Index(es):