lib/ruby_php_serialization/parser.y in divoxx-ruby-php-serialization-0.2.1 vs lib/ruby_php_serialization/parser.y in divoxx-ruby-php-serialization-0.2.2
- old
+ new
@@ -28,13 +28,17 @@
string : 's' ':' NUMBER ':' STRING { result = val[4] }
;
object : 'O' ':' NUMBER ':' STRING ':' NUMBER ':' '{' attribute_list '}'
{
- result = Object.const_get(val[4]).new
-
- val[9].each do |(attr_name, value)|
- result.instance_variable_set("@#{attr_name}", value)
+ if Object.const_defined?(val[4])
+ result = Object.const_get(val[4]).new
+
+ val[9].each do |(attr_name, value)|
+ result.instance_variable_set("@#{attr_name}", value)
+ end
+ else
+ result = Struct.new(val[4], *val[9].map { |(k,v)| k.to_sym }).new(*val[9].map { |(k,v)| v })
end
}
;
attribute_list : attribute_list attribute { result = val[0] << val[1] }
\ No newline at end of file