Files & JSON

Writing and reading a file

File.write(path, contents) writes a string to disk in one call β€” no explicit open/close ceremony for the simple case. File.read(path) reads the whole file back as one string:

File.write("notes.txt", "hello")
puts File.read("notes.txt")   # hello

Both are class methods on File β€” no block, no with/defer needed for a one-shot write-then-read. (Ruby also has a block form, File.open(path) { |f| ... }, for streaming line by line, but File.write/File.read cover almost everything you'll need for now.)