Sha256: d9ff68d134fa21512b2bc18da476c0b199496c4305cd6d3d0df3405384ddd604
Contents?: true
Size: 511 Bytes
Versions: 6
Compression:
Stored size: 511 Bytes
Contents
class String # The reverse of +camelcase+. Makes an underscored of a camelcase string. # # Changes '::' to '/' to convert namespaces to paths. # # Examples # # "SnakeCase".underscore #=> "snake_case" # "Snake-Case".underscore #=> "snake_case" # "SnakeCase::Errors".underscore #=> "snake_case/errors" # def underscore gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end end
Version data entries
6 entries across 5 versions & 1 rubygems