Class: String

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

Overview

extend ruby String class

Instance Method Summary collapse

Instance Method Details

#camelize(first_letter_in_uppercase = :upper) ⇒ Object



30
31
32
33
34
# File 'lib/langrove/ext/string.rb', line 30

def camelize(first_letter_in_uppercase = :upper)
  s = gsub(/\/(.?)/){|x| "::#{x[-1..-1].upcase unless x == '/'}"}.gsub(/(^|_)(.)/){|x| x[-1..-1].upcase}
  s[0...1] = s[0...1].downcase unless first_letter_in_uppercase == :upper
  s
end

#underscoreObject



10
11
12
13
14
15
16
# File 'lib/langrove/ext/string.rb', line 10

def underscore
  gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end