From: Daniel Schierbeck Date: 2006-08-20T18:20:16+09:00 Subject: Re: Convert "ThisIsSomeString" to "this_is_some_string"? ara.t.howard@noaa.gov wrote: > def snake_case string > return string unless string =~ %r/[A-Z]/ > reversed_words = string.reverse.scan(%r/[A-Z]+|[^A-Z]*[A-Z]+?|[^A-Z]+/) > reversed_words.reverse.map{|word| > word.reverse.downcase}.join('_').gsub(%r/_+/,'_') I'm not sure you want to label these as bugs: "FOO_Bar" => "fo_o_bar" "FOO_bar" => "fo_o_bar" But this probably is: "FOO_BAR" => "fo_o_bar" Cheers, Daniel