How to test whether IO object is open for writing

Given an object of type IO (respectively File), what is the easiest way
to see whether it is open for writing?

I could try to write the null string to the object and, if I get an
exception, assume that it is not writeable, but aside from the fact that
seems to be a rather crude way, it has the disadvantage that I can’t
distinguish between an IO object does not allow writing, and one which
is open for writing, but where writing fails due to, say, a network
error.

http://www.ruby-doc.org/stdlib-2.0/libdoc/fcntl/rdoc/Fcntl.html - there
you’ll find s.fcntl(Fcntl::F_GETFL, 0) example.

Thanks a lot!