Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That delay until the next garbage collection is a big caveat. While you might get away with this for file handles in some situations (honestly, I'm not sure that File#close really guarantees a write to disk anyway), it makes this technique essentially useless for mutexes.

(Edit: I should also point out that that's a function-scoped variable, not a lexically-scoped variable. Ruby doesn't have lexically-scoped variables.)



  File.open('path', 'w') do |f|
    f << something
  end
will do what you want


It might be good to read the whole discussion, particularly noting what I personally have said, before making conclusions about what I want.


I should have simply explained that my example will close the file handle and flush the changes out at the end of the block passed to the anonymous file handle, instead of making a statement about your wants.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: