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



16
17
18
19
20
# File 'lib/sweet/hacks.rb', line 16

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



21
22
23
24
# File 'lib/sweet/hacks.rb', line 21

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