Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/frenchy/core_ext.rb
Instance Method Summary collapse
Instance Method Details
#camelize ⇒ Object
11 12 13 |
# File 'lib/frenchy/core_ext.rb', line 11 def camelize dup.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } end |
#constantize ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/frenchy/core_ext.rb', line 15 def constantize names = self.split('::') names.shift if names.empty? || names.first.empty? constant = Object names.each do |name| constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) end constant end |
#underscore ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/frenchy/core_ext.rb', line 27 def underscore dup.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |