Class: String

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

Overview

These are pulled out of ActiveSupport

Instance Method Summary collapse

Instance Method Details

#camelize(first_letter_in_uppercase = :upper) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/string_ext.rb', line 4

def camelize(first_letter_in_uppercase = :upper)
  if first_letter_in_uppercase == :upper
    gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  else
    self[0..0].downcase + camelize[1..-1]
  end
end

#demodulizeObject



20
21
22
# File 'lib/string_ext.rb', line 20

def demodulize
  gsub(/^.*::/, '')
end

#underscoreObject



12
13
14
15
16
17
18
# File 'lib/string_ext.rb', line 12

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