Sha256: 81676c3a31f57ea3b76204ef7c4f152d62b009717cc21e2b1593c9353073d125

Contents?: true

Size: 426 Bytes

Versions: 12

Compression:

Stored size: 426 Bytes

Contents

# frozen_string_literal: true

module Bckbn
  module CoreExt
    module StringExt
      refine String do
        def underscore
          copy = dup
          copy.gsub("::", "/")
          copy.gsub!(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
            (::Regexp.last_match(1) || ::Regexp.last_match(2)) << "_"
          end
          copy.tr!("-", "_")
          copy.downcase!
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
bckbn-3.0.1 lib/bckbn/core_ext.rb
bckbn-3.0.0 lib/bckbn/core_ext.rb
bckbn-2.2.1 lib/bckbn/core_ext.rb
bckbn-2.1.1 lib/bckbn/core_ext.rb
bckbn-2.1.0 lib/bckbn/core_ext.rb
bckbn-2.0.0 lib/bckbn/core_ext.rb
bckbn-1.1.0 lib/bckbn/core_ext.rb
bckbn-1.0.0 lib/bckbn/core_ext.rb
bckbn-0.2.0 lib/bckbn/core_ext.rb
bckbn-0.1.2 lib/bckbn/core_ext.rb
bckbn-0.1.1 lib/bckbn/core_ext.rb
bckbn-0.1.0 lib/bckbn/core_ext.rb