Class: String

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

Instance Method Summary collapse

Instance Method Details

#camelize(first_letter_in_uppercase = true) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/helper.rb', line 46

def camelize(first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
  else
    self.first + camelize(self)[1..-1]
  end
end

#underscoreObject



38
39
40
41
42
43
44
# File 'lib/helper.rb', line 38

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