"Jos Backus" <jos / catnook.com> schrieb im Newsbeitrag 
news:20041204195115.GA83981 / lizzy.catnook.com...
> Another question... How do I access the File open mode ("w" in this case) 
> on a
> File object?  Example:
>
> class Foo
>  def initialize(file)
>    begin
>      yield self
>    ensure
>      # We only want to call finalize when the file was opened for writing;
>      # The following doesn't work, but how _do_ you do this?
>      finalize(file) if file.mode.writable? # file was opened with mode "w"
>    end
>  end
>  def finalize(file)
>    file.puts "END"
>  end
> end
>
> File.open("foo", "w") do |file|
>  a = Foo.new(file) do
>    # ... Use a ...
>  end
> end

First of all, I know no other way than to just try to write to the file and 
see what happens.  Maybe writing an empty string is a solution on some 
(all?) platforms.

But I think usually you don't need that info: if a method requires an IO 
object open for writing then it simply uses it that way and you get bitten 
by an exception if it's not open for writing.  Similar applies for files 
needed for reading.

What is the scenario where you need that?

Kind regards

    robert