Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ext.rb

Instance Method Summary collapse

Instance Method Details

#camelize(leading_caps = true) ⇒ Object



10
11
12
13
# File 'lib/ext.rb', line 10

def camelize(leading_caps = true)
  s = self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  s = leading_caps ? s : s[0...1].downcase + s[1..-1]
end

#underscoreObject



2
3
4
5
6
7
8
# File 'lib/ext.rb', line 2

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