This is my hash:
tempData = {\"a\" => 100, \"here\" => 200, \"c\" => \"hello\"}
I need to access the hash keys as a method like:>
There is another way to do this.
JSON.parse(tempData.to_json, object_class: OpenStruct)
that will give object
#
In this way nested hash
also will be converted to OpenStruct Object
tempData = {a: { b: { c: 3}}, foo: 200, msg: 'test msg'}
obj = JSON.parse(tempData.to_json, object_class: OpenStruct)
Now we are able to call
obj.a.b.c # 3
obj.foo # 200
obj.msg # 'test msg'
Hope this will help someone.