From: Robert Klemme Date: 2009-10-27T01:05:50+09:00 Subject: Re: file open failure test 2009/10/26 Derek Smith : > Bertram Scharpf wrote: >> Am Montag, 26. Okt 2009, 18:40:20 +0900 schrieb Robert Klemme: >>> If you just want the boolean information whether the open succeeded or >>> not you can do this: >>> >>> irb(main):010:0> File.open("mm").close || true rescue false >>> => true >>> irb(main):011:0> File.open("not existent").close || true rescue false >>> => false >> >> If you just want to test then ask: >> >>   File.stat("xx").readable? >> >> As Robert pointed out it is better straight to do what you want to >> do and catch the exceptions where they happen. > Thanks you guys!  I understand, but coming from (nasty) Perl land there > are > differences. Indeed. The OO in Ruby is significantly different (and better) than that in Perl. I suggest reading one or more of these: - online tutorials about Ruby - Pickaxe (only an old version available online via http://www.ruby-doc.org/) - David's "Well-Grounded Rubyist" >  But why the .close here File.open("mm").close ? > What does it do... auto close at end of the block? There is no block (no spoon either btw.). The file is opened and closed immediately. But as said, rather use the block form without beforehand checks. See also my blog article for some more discussion on methods with blocks: http://blog.rubybestpractices.com/posts/rklemme/001-Using_blocks_for_Robustness.html Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/