Create an object from an XML string in Ruby

I am trying to deserialize an object from XML to Ruby.

Something simple:

u = User.new({:client_key => "Bar"})
v = User.new(u.to_xml)

I get an error message:

NoMethodError: undefined method 'stringify_keys!' for #String: 0x20fc7cc>

I'm not sure what I need to do to get a string from XML into an object.

Update: @avdi gave me a hint. I expected from_xml to be a self method. You must create an object first.

v = User.new
v.from_xml(s)
+3
source share

Source: https://habr.com/ru/post/1698827/


All Articles