Sha256: 78118168f13fcc5fcad60d15cb3616479128fc44ded6c3a493e09e0933395bde

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Rodauth
  module PrefixExtensions
    unless String.method_defined?(:delete_prefix)
      refine(String) do
        def delete_suffix(suffix)
          suffix = suffix.to_s
          len = suffix.length
          return dup unless len.positive? && index(suffix, -len)

          self[0...-len]
        end

        def delete_prefix(prefix)
          prefix = prefix.to_s
          return dup unless rindex(prefix, 0)

          self[prefix.length..-1]
        end
      end
    end

    unless String.method_defined?(:delete_suffix!)
      refine(String) do
        def delete_suffix!(suffix)
          suffix = suffix.to_s
          chomp! if frozen?
          len = suffix.length
          return unless len.positive? && index(suffix, -len)

          self[-len..-1] = ""
          self
        end
      end
    end
  end

  module RegexpExtensions
    unless Regexp.method_defined?(:match?)
      refine(Regexp) do
        def match?(*args)
          !match(*args).nil?
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rodauth-oauth-0.10.4 lib/rodauth/oauth/refinements.rb
rodauth-oauth-0.10.3 lib/rodauth/oauth/refinements.rb
rodauth-oauth-0.10.2 lib/rodauth/oauth/refinements.rb
rodauth-oauth-0.10.1 lib/rodauth/oauth/refinements.rb
rodauth-oauth-0.10.0 lib/rodauth/oauth/refinements.rb
rodauth-oauth-0.9.3 lib/rodauth/oauth/refinements.rb
rodauth-oauth-0.9.2 lib/rodauth/oauth/refinements.rb
rodauth-oauth-0.9.1 lib/rodauth/oauth/refinements.rb
rodauth-oauth-0.9.0 lib/rodauth/oauth/refinements.rb
rodauth-oauth-0.8.0 lib/rodauth/oauth/refinements.rb