How can I convert a hash into a struct in ruby?
Given this:
h = { :a => 1, :b => 2 }
s.a == 1
s.b == 2
If it doesn't specifically have to be a Struct
and instead can be an OpenStruct
:
pry(main)> require 'ostruct'
pry(main)> s = OpenStruct.new(h)
=> #<OpenStruct a=1, b=2>
pry(main)> puts s.a, s.b
1
2