lib/flex_struct.rb in flex_struct-0.1.0 vs lib/flex_struct.rb in flex_struct-0.1.1

- old
+ new

@@ -1,14 +1,16 @@ # A drop-in replacement for Struct which adds a more flexible initialize method class FlexStruct autoload :VERSION, "flex_struct/version" + autoload :Frozen, "flex_struct/frozen" + autoload :Initializer, "flex_struct/initializer" - def self.new(*args) + def self.new(*args, &block) Struct.new(*args) do - def initialize(*args, **kwargs) - super(*args) - kwargs.each { |key, val| self[key] = val } - yield self if block_given? - end + module_eval(&block) if block + + # Insert our `initialize` method into the ancestors chain so it can be + # overridden by `block` if necessary + include Initializer end end end