Method: Hyperb::Utils#underscore
- Defined in:
- lib/hyperb/utils.rb
#underscore(camel_cased_word) ⇒ Object
based on api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-underscore
underscores and symbolize a string
63 64 65 66 67 68 69 70 71 |
# File 'lib/hyperb/utils.rb', line 63 def underscore(camel_cased_word) return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/ word = camel_cased_word.to_s.gsub(/::/, '/') 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.to_sym end |