Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/leaves/core_ext/string.rb
Instance Method Summary collapse
-
#camelize ⇒ Object
Converts strings to UpperCamelCase.
-
#underscore ⇒ Object
The reverse of
camelize
.
Instance Method Details
#camelize ⇒ Object
Converts strings to UpperCamelCase. – Graciously borrowed from Rails & ActiveSupport svn.rubyonrails.org/rails/tags/rel_2-0-2/activesupport/lib/active_support/inflector.rb
7 8 9 |
# File 'lib/leaves/core_ext/string.rb', line 7 def camelize self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } end |
#underscore ⇒ Object
The reverse of camelize
. Makes an underscored form from the expression in the string. – Graciously borrowed from Rails & ActiveSupport svn.rubyonrails.org/rails/tags/rel_2-0-2/activesupport/lib/active_support/inflector.rb
15 16 17 18 19 20 21 |
# File 'lib/leaves/core_ext/string.rb', line 15 def underscore self.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |