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

serialization.rb

This Ruby code snippet demonstrates serializing a Ruby hash (representing a person) into a string using Marshal.dump and then writing this serialized string to a file named person.dat. The Marshal.dump method converts the hash into a binary string, which is then saved to the file.

Ruby code snippet

person = { name: "Alice", age: 30 }
#=> {name: "Alice", age: 30}
serialized_person = Marshal.dump(person)
#=> "\x04\b{\a:\tnameI\"\nAlice\x06:\x06ET:\bagei#"

File.open('input/serialization/person.dat', 'wb') do |file|
  file.write(serialized_person)
end
#=> 30

Executed with Ruby 3.4.5.