From: dblack@... Date: 2002-09-16T09:25:08+09:00 Subject: Re: camelCaseTo_ruby_case.rb ?? Hello -- On Mon, 16 Sep 2002, [iso-8859-1] Thomas S�ndergaard wrote: > Hi, > > I'll be converting my ruby code from camelCase to ruby_case. Is there a > script out there to get me going? > > It should be trivial, but if it exists...there are better things I can do > with my time :-) I'm almost certainly reinventing_the_wheel, and probably doing it badly, but I don't mind having this hanging around on my system, so here it is: #!/usr/bin/ruby -wp BEGIN { class String def decamel gsub!(/\b[^\WA-Z]+[A-Z].*?\b/) do |x| x.gsub!(/[A-Z][^\WA-Z]+/) {|s| "_" + s.downcase } x.gsub!(/[A-Z][A-Z]+/) {|s| "_" + s } x end end end } $_.decamel I'm assuming that class names like this should not be changed: class SomeClass and that in cases like this: someDBMMethod "DBM" should be kept uppercase. Comments, changes, dismissal, etc. welcome :-) David -- David Alan Black | Register for RubyConf 2002! home: dblack@candle.superlink.net | November 1-3 work: blackdav@shu.edu | Seattle, WA, USA Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com