Class: String

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

Overview

TODO find those things in JRuby

Instance Method Summary collapse

Instance Method Details

#camelize(first_letter_in_uppercase = :upper) ⇒ Object



33
34
35
36
37
# File 'lib/sweet/hacks.rb', line 33

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



38
39
40
41
# File 'lib/sweet/hacks.rb', line 38

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