Skip to content

Instantly share code, notes, and snippets.

@ascendbruce
Created October 16, 2013 15:10
Show Gist options
  • Save ascendbruce/7009252 to your computer and use it in GitHub Desktop.
Save ascendbruce/7009252 to your computer and use it in GitHub Desktop.
Ruby File open read/write examples
File.open("/usr/local/widgets/data").each do |line|
    puts line if line =~ /blue/
end



logfile = File.new("/tmp/log", "w")

logfile.close



File.expand_path('~/tmp')


fh = Tempfile.new('tmp')
fh.sync = true # autoflushes
10.times { |i| fh.puts i }
fh.rewind
puts 'Tmp file has: ', fh.readlines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment