Module: MonkeyPatch::String::Inflectors

Included in:
String
Defined in:
ruby/trema/monkey-patch/string/inflectors.rb

Instance Method Summary collapse

Instance Method Details

#camelizeObject



22
23
24
25
26
# File 'ruby/trema/monkey-patch/string/inflectors.rb', line 22

def camelize
  self.split( /[^a-z0-9]/i ).map do | each |
    each.capitalize
  end.join
end

#demodulizeObject



29
30
31
# File 'ruby/trema/monkey-patch/string/inflectors.rb', line 29

def demodulize
  self.gsub /^.*::/, ''
end

#underscoreObject



34
35
36
37
38
39
40
41
42
# File 'ruby/trema/monkey-patch/string/inflectors.rb', line 34

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