From: Phillip Gawlowski Date: 2008-04-09T15:28:32+09:00 Subject: Re: output of a method to file? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Zoe Phoenix wrote: | directory\rubyprograms\cities.rb:33:in 'initialize': | ubyfiles tylist-city1.txt (Errno::EINVAL) | from directory\rubyprograms\cities.rb:33:in | 'open' | from directory\rubyprograms\cities.rb:33 | | ******** | | | There's something wrong with the code, I know, but I'm not sure what. Yes, but something simple, actually, and easy to fix: Ruby, like other programming languages, uses the backslash "\" as an escape character. That means (in simple terms), Ruby ignores the character directly after the backslash. Usually, because that character means something special. An example is the newline character "\n", which produces a newline in a file or screen output, for example. (Like pressing enter, just done by Ruby). printf "This text has\na new line" #demonstrates the \n character. You have two options: You can change your back slashes to forward slashes (from \ to /), or add another backslash to escape your backslashes: This happens when you try to open the file to write into it. The possible solutions: File::open("c:\\rubyfiles\\citylist-#{save_as}.txt", 'w') #Escaping the backslashes File::open("c:/rubyfiles/citylist-#{save_as}.txt", 'w') #Using forward slashes Both solutions are fine. Windows can handle forward slashes, too (at least in Windows XP). I hope that helps. :) - -- Phillip Gawlowski Twitter: twitter.com/cynicalryan ~ - You know you've been hacking too long when... ...after days with YACC, you start to parse your conversations. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkf8YhEACgkQbtAgaoJTgL9e7wCgjK7dGrSuohp0WJMBvUoIPfaw 7zYAnjKMnookgkBPjZygZDlnnslVtS0y =wcVf -----END PGP SIGNATURE-----