Sha256: 297a3f2a6dc7f0cc442c6809fc6f5853e5df56ebb4ac530ccfb1f6c2c51db857
Contents?: true
Size: 332 Bytes
Versions: 6
Compression:
Stored size: 332 Bytes
Contents
# add method to String class class String # add method :underscore for String class to convert Class name in camelcase def underscore word = dup word.gsub!(/::/, '/') word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.tr!('-', '_') word.downcase! word end end
Version data entries
6 entries across 6 versions & 1 rubygems