Sha256: 494f83d87e5b13ac34dee1cc2581517488efa9cc8d84ec7db4dcfce631f4403a

Contents?: true

Size: 388 Bytes

Versions: 12

Compression:

Stored size: 388 Bytes

Contents

class String

  # converts a camel cased word to an underscored word
  def underscore
    self.gsub(/::/, '/').
        gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
        gsub(/([a-z\d])([A-Z])/,'\1_\2').
        tr("-", "_").
        downcase
  end

  # Gets the constant when it is defined that corresponds to this string
  def classify
    Object.const_get self
  end
  
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
casualjim-caricature-0.5.0 lib/core_ext/string.rb
casualjim-caricature-0.6.0 lib/core_ext/string.rb
casualjim-caricature-0.6.1 lib/core_ext/string.rb
caricature-0.7.6 lib/caricature/core_ext/string.rb
caricature-0.7.5 lib/caricature/core_ext/string.rb
caricature-0.7.2 lib/core_ext/string.rb
caricature-0.7.1 lib/core_ext/string.rb
caricature-0.7.0 lib/core_ext/string.rb
caricature-0.6.3 lib/core_ext/string.rb
caricature-0.5.0 lib/core_ext/string.rb
caricature-0.6.1 lib/core_ext/string.rb
caricature-0.6.0 lib/core_ext/string.rb