Skip to content

Instantly share code, notes, and snippets.

@wjessop
Created February 20, 2011 17:53
Show Gist options
  • Save wjessop/836152 to your computer and use it in GitHub Desktop.
Save wjessop/836152 to your computer and use it in GitHub Desktop.
… Create a file:
octobrain:~ will$ echo foo > /tmp/foo
… launch IRB:
octobrain:~ will$ irb
ruby-1.9.2-p0 > f = File.open('/tmp/foo')
=> #<File:/tmp/foo>
ruby-1.9.2-p0 > f.flock(File::LOCK_EX)
=> 0
… Meanwhile in another terminal:
octobrain:~ will$ cat /tmp/foo
foo
octobrain:~ will$ echo bar > /tmp/foo
octobrain:~ will$ cat /tmp/foo
bar
– Back in IRB:
ruby-1.9.2-p0 > f.close
=> nil
ruby-1.9.2-p0 >
… The file contents:
octobrain:~ will$ cat /tmp/foo
bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment