Sha256: cc703348e4a312ef50f3c47bc2d71d51b282fc186a3afb28fa771d71df6dd889

Contents?: true

Size: 637 Bytes

Versions: 1

Compression:

Stored size: 637 Bytes

Contents

class String
  def first_caps
    self.split(/ /).map{|x| x.capitalize}.join(' ')
  end
  def my_underscore #fills in the gap in rails inflectors, since their #underscore method only works for CamelCase
    self.downcase.gsub(/\s+/,"_")
  end
  def titleize #overloads
    titleized_words = self.split.collect do |word| 
      unless word.match(/[A-Z]{2}/)
        word.underscore.humanize.gsub(/\b('?[a-z])/) { $1.capitalize }
        #humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize }  #this is from rails source and didn't work
      else
        word
      end
    end
      
    titleized_words.join(' ')
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pixelearth-3.2.4 config/initializers/string.rb