/ Published in: Ruby
URL: http://rubyforge.org/snippet/detail.php?type=snippet&id=1
A very useful snippet found in this thread.
However it does not do deep conversion, that is, for a hash of hashes, you will get back a struct of hashes.
Expand |
Embed | Plain Text
class Hash def to_struct Struct.new(*keys).new(*values) end end # then use it like this h = {:foo => 'bar', :baz => 'boz'} s = h.to_struct("NameOfMyStruct")
You need to login to post a comment.
