Method: Animoto::Support::String#underscore

Defined in:
lib/animoto/support/string.rb

#underscoreString

Transforms this string from camel case to underscore-form. Downcases the entire string.

Examples:

"ThisIsACamelCasedString" # => "this_is_a_camel_cased_string"

Returns:

  • (String)

    the underscored form of this string



23
24
25
# File 'lib/animoto/support/string.rb', line 23

def underscore
  self.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
end