Class: HumanError::Utilities::String
- Inherits:
-
Object
- Object
- HumanError::Utilities::String
- Defined in:
- lib/human_error/utilities/string.rb
Class Method Summary collapse
Class Method Details
.underscore(other) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/human_error/utilities/string.rb', line 4 def self.underscore(other) word = other.to_s.gsub('::', '/') word.gsub!(/(?:([A-Za-z\d])|^)(?=\b|[^a-z])/) do "#{Regexp.last_match(1)}#{Regexp.last_match(1) && ''}" end word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.tr!('-', '_') word.downcase! word end |