Sha256: b66239f711495074ac6aa3afd935ea04d16b5f756614ddee76c77b32affb59d3

Contents?: true

Size: 357 Bytes

Versions: 2

Compression:

Stored size: 357 Bytes

Contents

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

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

  def to_constant
    Object.const_get(self)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vundabar-0.2.0 lib/vundabar/utilities.rb
vundabar-0.1.0 lib/vundabar/utilities.rb