Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/githooker/core_ext/string/inflections.rb

Instance Method Summary collapse

Instance Method Details

#camelizeObject



11
12
13
# File 'lib/githooker/core_ext/string/inflections.rb', line 11

def camelize()
  self.dup.camelize!
end

#camelize!Object



15
16
17
# File 'lib/githooker/core_ext/string/inflections.rb', line 15

def camelize!()
  self.replace(self.split(/[\W_]+/).collect(&:capitalize).join)
end

#constantizeObject



2
3
4
5
6
7
8
9
# File 'lib/githooker/core_ext/string/inflections.rb', line 2

def constantize()
  names = self.split('::')
  names.shift if names.empty? || names.first.empty?

  names.inject(Object) { |obj, name|
    obj = obj.const_defined?(name) ? obj.const_get(name) : obj.const_missing(name)
  }
end

#dasherizeObject



48
49
50
# File 'lib/githooker/core_ext/string/inflections.rb', line 48

def dasherize()
  self.dup.dasherize!
end

#dasherize!Object



44
45
46
# File 'lib/githooker/core_ext/string/inflections.rb', line 44

def dasherize!()
  self.underscore!.gsub!(/_/, '-')
end

#titleizeObject Also known as: titlize



35
36
37
# File 'lib/githooker/core_ext/string/inflections.rb', line 35

def titleize
  self.dup.titleize!
end

#titleize!Object Also known as: titlize!



28
29
30
31
32
# File 'lib/githooker/core_ext/string/inflections.rb', line 28

def titleize!
  self.tap { |title|
    title.replace(title.split(/\b/).collect(&:capitalize).join)
  }
end

#underscoreObject



40
41
42
# File 'lib/githooker/core_ext/string/inflections.rb', line 40

def underscore()
  self.dup.underscore!
end

#underscore!Object



19
20
21
22
23
24
25
26
# File 'lib/githooker/core_ext/string/inflections.rb', line 19

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