lib/cinnamon_serial/base.rb in cinnamon_serial-2.0.0 vs lib/cinnamon_serial/base.rb in cinnamon_serial-2.1.0

- old
+ new

@@ -22,11 +22,11 @@ :obj, :opts, :klasses def initialize(obj, opts = {}, klasses = Set.new) - @obj = obj + @obj = normalize_object(obj) @opts = opts || {} @klasses = klasses materialize_data execute_hydrate_blocks @@ -88,8 +88,15 @@ instance_eval(&block) end end nil + end + + # We would like to support hashes, but would rather stay object-based. So what we + # can do is just simply convert hashes to OpenStruct objects so they behave more like + # objects. + def normalize_object(obj) + obj.is_a?(Hash) ? OpenStruct.new(obj) : obj end end end