How about this one?

class MyString < String
   def snake_case(group = true)
     return self if self == ''
     if group
       if self =~ /\b(?:[A-Z]+)(?:[A-Z][a-z])/
         gsub(/\b([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/\s/,'_').downcase
       else
         gsub(/([a-zA-Z])([A-Z])/,'\1_\2').gsub(/\s/,'_').downcase
       end
     else
       gsub(/([a-zA-Z])(?=[A-Z])/,'\1_\2').gsub(/\s/,'_').downcase
     end
   end
end

a = MyString.new("fooBar")
puts a.snake_case
b = MyString.new("FOOBar")
puts b.snake_case
c = MyString.new("FOOOOBar")
puts c.snake_case


When ran:

foo_bar
foo_bar
foooo_bar


Kirk Haines