extend base String class to add a snakecase method

This commit is contained in:
onyx-and-iris 2023-07-09 23:48:46 +01:00
parent 875a5b6a23
commit 48b9e931c4

View File

@ -0,0 +1,19 @@
module Voicemeeter
module Ext
module String
module SnakeCase
class ::String
def snakecase
self
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
.tr("-", "_")
.gsub(/\s/, "_")
.gsub(/__+/, "_")
.downcase
end
end
end
end
end
end