How do I use OpenStruct’s marshal_load utility? It doesn’t appear to work as intended.
The docs give this example, but it doesn’t appear to work.
require 'ostruct'
event = OpenStruct.new
hash = { 'time' => Time.now, 'title' => 'Birthday Party' }
event.marshal_load(hash)
event.title # => nil
If not this way, how do I load a hash into an OpenStruct (without using the constructor)?
For context: I’m loading a hash in from a YAML file and loading it into an existing instance of an OpenStruct subclass.
The
marshal_loadmethod exists to provide support forMarshal.load.The easiest way to programmatically load a hash into a struct is using send: