Method: String#underscore
- Defined in:
- lib/extra/string.rb
#underscore ⇒ Object
Removes everything except letters and spaces, replaces spaces with an underscore, and lowercases the string. The opposite of the camelcase convention.
Example: "foo bar baz".underscore #=> "foo_bar_baz"
Returns: String
166 167 168 |
# File 'lib/extra/string.rb', line 166 def underscore gsub(/[^a-z ]+/, '').gsub(/ +/, '_').downcase end |