Sha256: e0008523667515eba26d08794bc1544e8d6845ee7b01282c0f5619484bb25d9c
Contents?: true
Size: 733 Bytes
Versions: 6
Compression:
Stored size: 733 Bytes
Contents
module Polyfill module V2_5 module Struct module ClassMethods def new(*args, keyword_init: false) obj = super(*args) if keyword_init attrs = args attrs.shift if attrs.first.class != Symbol ignore_warnings do obj.send(:define_method, :initialize) do |**kwargs| invalid_args = kwargs.reject { |k, _| attrs.include?(k) }.keys unless invalid_args.empty? raise ArgumentError, "unknown keywords: #{invalid_args.join(', ')}" end super(*kwargs.values_at(*attrs)) end end end obj end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems