Sha256: a38b14c0053a5c876aaca58142b5f4b5c64e79a55211dfad3083ad561be12276

Contents?: true

Size: 613 Bytes

Versions: 5

Compression:

Stored size: 613 Bytes

Contents

module Polyfill
  module V2_3
    module String
      module ClassMethods
        def new(*args)
          hash, others = args.partition { |arg| arg.is_a?(::Hash) }
          hash = hash.first
          encoding = hash && hash.delete(:encoding)

          if hash && !hash.keys.empty?
            raise ArgumentError, "unknown keyword: #{hash.keys.first}"
          end

          str = super(*others)
          str.encode!(encoding) if encoding
          str
        end
      end

      def +@
        frozen? ? dup : self
      end

      def -@
        frozen? ? self : dup.freeze
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
polyfill-1.0.0 lib/polyfill/v2_3/string.rb
polyfill-0.10.0 lib/polyfill/v2_3/string.rb
polyfill-0.9.0 lib/polyfill/v2_3/string.rb
polyfill-0.8.0 lib/polyfill/v2_3/string.rb
polyfill-0.7.0 lib/polyfill/v2_3/string.rb