Class: String

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

Instance Method Summary collapse

Instance Method Details

#constantizeObject



18
19
20
# File 'lib/bart_api/core_ext/string.rb', line 18

def constantize
  self.tr_s('- ', '_').split('_').map(&:capitalize).join
end

#titleizeObject



14
15
16
# File 'lib/bart_api/core_ext/string.rb', line 14

def titleize
  self.tr_s('- ', '_').split('_').map(&:capitalize).join(' ')
end

#underscoreObject



2
3
4
# File 'lib/bart_api/core_ext/string.rb', line 2

def underscore
  self.dup.underscore!
end

#underscore!Object



6
7
8
9
10
11
12
# File 'lib/bart_api/core_ext/string.rb', line 6

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