Heads up: This description was created by AI and might not be 100% accurate.

deserialization.rb

This Ruby code snippet demonstrates deserialization of data stored in a binary format using Marshal. It first reads the binary data from the file ‘person.dat’ and then uses Marshal.load to convert the binary string back into a Ruby hash object containing the name “Alice” and age 30. Marshal is used to serialize Ruby objects into a byte stream, and Marshal.load reconstructs the object from that stream.

Ruby code snippet

serialized_person = File.read('input/serialization/person.dat')
#=> "\u0004\b{\a:\tnameI\"\nAlice\u0006:\u0006ET:\bagei#"
Marshal.load(serialized_person)
#=> {name: "Alice", age: 30}

Executed with Ruby 3.4.5.