Skip to content

Instantly share code, notes, and snippets.

@jcoyne
Last active August 29, 2015 14:27
Show Gist options
  • Save jcoyne/cf7accb04d569b68128b to your computer and use it in GitHub Desktop.
Save jcoyne/cf7accb04d569b68128b to your computer and use it in GitHub Desktop.
irb(main):034:0> original = "Dude"
=> "Dude"
irb(main):035:0> serialized = Marshal.dump(original)
=> "\x04\bI\"\tDude\x06:\x06ET"
irb(main):036:0> File.open(statefile, 'a+b') do |f|
irb(main):037:1* f.write serialized
irb(main):038:1> end
irb(main):039:0> data = nil
=> nil
irb(main):046:0> File.open(statefile, 'a+b') do |f|
irb(main):047:1* f.rewind
irb(main):048:1> data = f.read
irb(main):049:1> end
=> "\x04\bI\"\tDude\x06:\x06ET"
irb(main):050:0> Marshal.load(data)
=> "Dude"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment