Module: SinatraResource::Utility
- Defined in:
- lib/utility.rb
Class Method Summary collapse
-
.underscore(camel_cased_word) ⇒ String
The reverse of
camelize
.
Class Method Details
.underscore(camel_cased_word) ⇒ String
The reverse of camelize
. Makes an underscored, lowercase form from the expression in the string.
Example:
"SourceGroup".underscore # => "source_group"
(This method was adapted from ActiveSupport 2.3.5)
16 17 18 19 20 21 22 |
# File 'lib/utility.rb', line 16 def self.underscore(camel_cased_word) camel_cased_word.to_s. gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr("-", "_"). downcase end |