From: Daniel Schierbeck Date: 2006-08-20T07:35:08+09:00 Subject: Re: Convert "ThisIsSomeString" to "this_is_some_string"? ara.t.howard@noaa.gov wrote: > here's a start: > > harp:~ > cat a.rb > def snake_case string > return string unless string =~ %r/[A-Z]/ > > string.reverse.scan(%r/[A-Z]+|[^A-Z]*[A-Z]+?|[^A-Z]+/).reverse.map{|word| > word.reverse.downcase}.join '_' > end Can we agree that "ABCde" => "ab_cde"? I still get an error when the original string has underscores in it: "foo_Bar" => "foo__bar" "foo_BAR" => "foo__bar" Too tired to figure out a solution right now, I'll get back to you in the morning (that'll probably be your night.) Cheers, Daniel