serialization.rb(serialization)
Using Marshal for Serialization
The Marshal provides a way to serialize Ruby objects into a binary format and then deserialize them back to Ruby objects.
Execution:
person = { name: "Alice", age: 30 }
#=> {:name=>"Alice", :age=>30}
serialized_person = Marshal.dump(person)
#=> "\x04\b{\a:\tnameI\"\nAlice\x06:\x06ET:\bagei#"
File.open('person.dat', 'wb') do |file|
file.write(serialized_person)
end
#=> 30
Executed with Ruby 3.3.6