lib/polyfill/v2_3/string.rb in polyfill-0.6.0 vs lib/polyfill/v2_3/string.rb in polyfill-0.7.0

- old
+ new

@@ -1,11 +1,29 @@ -require_relative 'string/class' -require_relative 'string/instance' - module Polyfill module V2_3 module String - include Class - include Instance + 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