mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-11-25 03:10:49 +00:00
extend base String class to add a snakecase method
This commit is contained in:
parent
875a5b6a23
commit
48b9e931c4
19
lib/voicemeeter/core_extensions/string/snakecase.rb
Normal file
19
lib/voicemeeter/core_extensions/string/snakecase.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user