lib/kwstruct.rb in kwstruct-0.1.0 vs lib/kwstruct.rb in kwstruct-0.2.0

- old
+ new

@@ -1,12 +1,14 @@ class KwStruct < Struct - VERSION = '0.1.0' + VERSION = '0.2.0' - def self.new(*members) - class_eval <<-RUBY - def initialize(#{members.map{|m| "#{m}: nil"}.join(', ')}) - super(#{members.join(', ')}) - end - RUBY - super + def self.new(*members, &block) + super.tap do |struct_class| + struct_class.class_eval <<-RUBY + def initialize(#{members.map{|m| "#{m}: nil"}.join(', ')}) + super(#{members.join(', ')}) + end + RUBY + end end end +