From: Ezra Zygmuntowicz Date: 2007-07-03T02:42:31+09:00 Subject: Re: de-camelcase a filename On Jul 2, 2007, at 9:41 AM, Bill Kelly wrote: > From: "Roseanne Zhang" >> How about this: >> "FooBarBaz".split(/(?=[A-Z])/).join('_').downcase > > Nice... (why didn't I think of that :) This is the cleanest I've come up with: class String # "FooBar".snake_case #=> "foo_bar" def snake_case gsub(/\B[A-Z]/, '_\&').downcase end end Cheers- -- Ezra Zygmuntowicz -- Lead Rails Evangelist -- ez@engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273)