Sha256: 4850777a0c7bce77fb276cce0801d3dbf6c1855168212e9c5a84292799d48299

Contents?: true

Size: 444 Bytes

Versions: 7

Compression:

Stored size: 444 Bytes

Contents

class Nori
  module CoreExt
    module String

      # Returns the String in snake_case.
      def snakecase
        str = dup
        str.gsub! /::/, '/'
        str.gsub! /([A-Z]+)([A-Z][a-z])/, '\1_\2'
        str.gsub! /([a-z\d])([A-Z])/, '\1_\2'
        str.tr! ".", "_"
        str.tr! "-", "_"
        str.downcase!
        str
      end unless method_defined?(:snakecase)

    end
  end
end

String.send :include, Nori::CoreExt::String

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
nori-ng-1.6-2.3.0 lib/nori/core_ext/string.rb
nori-2.3.0 lib/nori/core_ext/string.rb
nori-2.2.0 lib/nori/core_ext/string.rb
nori-2.1.0 lib/nori/core_ext/string.rb
nori-2.0.4 lib/nori/core_ext/string.rb
nori-2.0.3 lib/nori/core_ext/string.rb
nori-2.0.0 lib/nori/core_ext/string.rb