Robert Klemme
1/30/2009 12:37:00 PM
2009/1/30 Nebs Petrovic <nebs_man@hotmail.com>:
> Thanks, it works now. It had to do with opening for writing only. I
> guess it makes sense that you can't open a file for reading if it
> doesn't exist, I just thought that if you open for reading AND writing
> it would be smart enough to create it anyways and just return nil on a
> "gets" or similar request. Anyways, thanks again.
Well, you can do that but you need a different open mode: open for
writing /plus/ reading:
13:37:55 ~$ ls -l foo
ls: cannot access foo: No such file or directory
13:37:58 ~$ irb
Ruby version 1.8.7
irb(main):001:0> File.open("foo","w+") {|io|
io.puts("test");io.seek(0,IO::SEEK_SET); p io.read}
"test\n"
=> nil
irb(main):002:0> exit
13:38:10 ~$ ls -l foo
-rw-r--r-- 1 RKlemme Domain Users 5 Jan 30 13:38 foo
13:38:11 ~$
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end