class String
Public Instance Methods
camel_case()
click to toggle source
# File lib/string.rb, line 21 def camel_case return self if self !~ /_/ && self =~ /[A-Z]+.*/ split('_').map{|e| e.capitalize}.join end
reformat()
click to toggle source
# File lib/string.rb, line 17 def reformat self.split(/[\.|\s|\-](?=[\w])/).join(' ').title_case end
title_case()
click to toggle source
# File lib/string.rb, line 2 def title_case title = self.split out = '' minus = ['of', 'the', 'in', 'and'] title.each_with_index do |word, i| word = ((i > 0 and minus.include?(word.downcase)) ? word.downcase : word.capitalize) out += ' %s' % word end return out.strip end
underscore()
click to toggle source
# File lib/string.rb, line 26 def underscore self.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2') .gsub(/([a-z\d])([A-Z])/,'\1_\2') .tr("-", "_") .downcase end