Class: SuperString

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

Class Method Summary collapse

Class Method Details

.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object



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

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

.underscore(string) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/ext/super_string.rb', line 11

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