Create an object in Ruby
Just create a json data and use OpenStruct to create object
data = { user: { profile: {name: 'LV', age: 28} } }.to_json result = JSON.parse(data, object_class: OpenStruct) puts result.user.profile.name #=> 'LV'
Just create a json data and use OpenStruct to create object
data = { user: { profile: {name: 'LV', age: 28} } }.to_json result = JSON.parse(data, object_class: OpenStruct) puts result.user.profile.name #=> 'LV'