Sha256: fd34f3bd1659db0455318d25f6b77bb8c11c8d819bdafbeaf4554390cefccc97

Contents?: true

Size: 683 Bytes

Versions: 2

Compression:

Stored size: 683 Bytes

Contents

class String
  def snakize
    gsub!("::", "/")
    gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    gsub!(/([a-z0-9])([A-Z])/, '\1_\2')
    tr!("-", "_")
    downcase!
    self
  end

  def camelize
    return self if self !~ /_/ && self =~ /[A-Z]+.*/
    split("_").map(&:capitalize).join
  end

  def constantize
    Object.const_get(self)
  end

  def pluralize
    gsub!(/([^aeiouy]|qu)y$/i, '\1ies')
    gsub!(/(ss|z|ch|sh|x)$/i, '\1es')
    gsub!(/(is)$/i, "es")
    gsub!(/(f|fe)$/i, "ves")
    gsub!(/(ex|ix)$/i, "ices")
    gsub!(/(a)$/i, "ae")
    gsub!(/(um|on)$/i, "a")
    gsub!(/(us)$/i, "i")
    gsub!(/(eau)$/i, "eaux")
    gsub!(/([^saeix])$/i, '\1s')
    self
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rollerskates-0.1.1 lib/rollerskates/utility.rb
rollerskates-0.1.0 lib/rollerskates/utility.rb