Method: Seahorse::Util.underscore
- Defined in:
- lib/seahorse/util.rb
.underscore(string) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the underscored version of the given string.
15 16 17 18 19 20 21 22 |
# File 'lib/seahorse/util.rb', line 15 def underscore(string) new_string = string.dup new_string.gsub!(@irregular_regex) { |word| "_#{@irregular_inflections[word]}" } new_string.gsub!(/([A-Z0-9]+)([A-Z][a-z])/, '\1_\2'.freeze) new_string = new_string.scan(/[a-z0-9]+|\d+|[A-Z0-9]+[a-z]*/).join('_'.freeze) new_string.downcase! new_string end |