Sha256: 763d169274c80dec6f6d79e9b4bd9394411207a4b773849577ceb8ba0e27eefe
Contents?: true
Size: 811 Bytes
Versions: 15
Compression:
Stored size: 811 Bytes
Contents
if RUBY_VERSION >= '2.0.0' && (Struct.new(:a, :keyword_init => true) && false rescue true) require 'backports/tools/alias_method_chain' eval %q[ class << Struct def new_with_keyword_init(*members, keyword_init: false, &block) klass = new_without_keyword_init(*members) if keyword_init members.shift unless members.first.is_a?(Symbol) arg_list = members.map { |m| "#{m}: nil"}.join(', ') setter = members.map { |m| "self.#{m} = #{m} " }.join("\n") klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def initialize(#{arg_list}) #{setter} end RUBY end klass.class_eval(&block) if block klass end Backports.alias_method_chain(self, :new, :keyword_init) end ], nil, __FILE__, __LINE__ - 19 end
Version data entries
15 entries across 15 versions & 1 rubygems