Serialization.rb

This content was produced by an LLM and could include errors.

This script creates a Ruby hash. It uses Marshal.dump to serialize the hash into a binary format, then writes that serialized data to the person.dat file.

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

Ruby 4.0.3