From: John Joyce Date: 2007-07-01T07:26:23+09:00 Subject: Re: de-camelcase a filename On Jun 30, 2007, at 3:17 PM, Bill Kelly wrote: > > From: "Swaroop C H" >> On 6/30/07, Aaron Smith wrote: >>> how can a take a string file name like MyTestCase.rb and change >>> it to >>> my_test_case.rb? >> I'm a novice at Ruby, but this might help: >> irb(main):013:0> 'MyTestCase'.gsub(/[A-Z]/) { >> irb(main):014:1* |p| '_' + p.downcase >> irb(main):015:1> } >> => "_my_test_case" >> then: >> irb(main):020:0> "_my_test_case"[1..-1] >> => "my_test_case" > > Here's another way: > > irb(main):078:0> "FooBarBaz".split(/(?=[A-Z])/).map{|w| > w.downcase}.join("_") > => "foo_bar_baz" > > > Regards, > > Bill > > > Just be careful of any code that has dependencies on the camelCaps version! You might even write a conditional require statement to check for both versions.