Skip to content

Instantly share code, notes, and snippets.

@dogweather
Last active December 29, 2015 13:59
Show Gist options
  • Save dogweather/7681360 to your computer and use it in GitHub Desktop.
Save dogweather/7681360 to your computer and use it in GitHub Desktop.
Read a file into a string.
contents = File.open('file.txt') { |f| f.read }
@dogweather
Copy link
Author

The block automatically closes the file when it completes.

@dogweather
Copy link
Author

Ruby 1.8+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment