Sha256: 1fe3c253910c13d416c0d93daf36d962b5aae40cc006c84182cf93571f8cd3a6

Contents?: true

Size: 425 Bytes

Versions: 1

Compression:

Stored size: 425 Bytes

Contents

# frozen_string_literal: true

module Logux
  module Utils
    refine String do
      def underscore
        return self unless /[A-Z-]|::/.match?(self)

        String.new(self).tap do |word|
          word.gsub!('::', '/')
          word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
          word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
          word.tr!('-', '_')
          word.downcase!
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logux-rack-0.1.0 lib/logux/utils.rb