Module: Polyfill::V2_3::String::ClassMethods

Defined in:
lib/polyfill/v2_3/string.rb

Instance Method Summary collapse

Instance Method Details

#new(*args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/polyfill/v2_3/string.rb', line 5

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.force_encoding(encoding) if encoding
  str
end