• in `open': no implicit conversion of nil into String (TypeError) from e

    From Cai Gengyang@21:1/5 to All on Mon Apr 11 20:31:14 2016
    This is my file which I saved as ex30.rb :

    filename = ARGV.first

    txt = open(filename)

    puts "Here's your file #{filename}:"
    print txt.read

    print "Type the filename again: "
    file_again = $stdin.gets.chomp

    txt_again = open(file_again)

    print txt_again.read

    This is the error I got when I tried to run it in my Terminal :

    CaiGengYangs-MacBook-Pro:GoatBoy CaiGengYang$ ruby ex30.rb
    ex30.rb:3:in `open': no implicit conversion of nil into String (TypeError)
    from ex30.rb:3:in `<main>'

    What's the error here ?

    Gengyang

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Klemme@21:1/5 to Cai Gengyang on Tue Apr 12 08:09:59 2016
    On 12.04.2016 05:31, Cai Gengyang wrote:
    This is my file which I saved as ex30.rb :

    filename = ARGV.first

    txt = open(filename)

    puts "Here's your file #{filename}:"
    print txt.read

    print "Type the filename again: "
    file_again = $stdin.gets.chomp

    txt_again = open(file_again)

    print txt_again.read

    This is the error I got when I tried to run it in my Terminal :

    CaiGengYangs-MacBook-Pro:GoatBoy CaiGengYang$ ruby ex30.rb
    ex30.rb:3:in `open': no implicit conversion of nil into String (TypeError)
    from ex30.rb:3:in `<main>'

    What's the error here ?

    Invoking the script without arguments.

    robert

    --
    remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cai Gengyang@21:1/5 to Robert Klemme on Tue Apr 12 22:34:33 2016
    What does "invoking the script without arguments" mean ?

    On Tuesday, April 12, 2016 at 2:10:08 PM UTC+8, Robert Klemme wrote:
    On 12.04.2016 05:31, Cai Gengyang wrote:
    This is my file which I saved as ex30.rb :

    filename = ARGV.first

    txt = open(filename)

    puts "Here's your file #{filename}:"
    print txt.read

    print "Type the filename again: "
    file_again = $stdin.gets.chomp

    txt_again = open(file_again)

    print txt_again.read

    This is the error I got when I tried to run it in my Terminal :

    CaiGengYangs-MacBook-Pro:GoatBoy CaiGengYang$ ruby ex30.rb
    ex30.rb:3:in `open': no implicit conversion of nil into String (TypeError)
    from ex30.rb:3:in `<main>'

    What's the error here ?

    Invoking the script without arguments.

    robert

    --
    remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sebastian Christ@21:1/5 to Cai Gengyang on Wed Apr 13 10:23:14 2016
    On 2016-04-12 22:34, Cai Gengyang <gengyangcai@gmail.com> wrote:
    What does "invoking the script without arguments" mean ?

    Are you sure that you've done all the exercises? You say you're now at Ex. 30, but obviously you didn't pay that much attention to Ex. 13, did you?

    Regards,
    Sebastian

    --
    Sebastian (Rudolfo) Christ
    http://rudolfochrist.github.io
    GPG Fingerprint: 306D 8FD3 DFB6 4E44 5061
    CE71 6407 D6F8 2AC5 55DD

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cai Gengyang@21:1/5 to Sebastian Christ on Wed Apr 13 09:08:16 2016
    Ok, it works now ! I was on exercise 15 (http://learnrubythehardway.org/book/ex15.html), not exercise 30 ... just named it ex30 randomly because I previously saved another file called ex15.

    CaiGengYangs-MacBook-Pro:GoatBoy CaiGengYang$ ruby ex30.rb ex30_sample.txt Here's your file ex30_sample.txt:
    This is stuff I typed into a file.
    It is really cool stuff.
    Lots and lots of fun to have in here.

    Type the filename again: ex30_sample.txt
    This is stuff I typed into a file.
    It is really cool stuff.
    Lots and lots of fun to have in here.

    I realised that I got the error because I initially forgot to create the 2nd sample.txt file




    On Wednesday, April 13, 2016 at 4:23:25 PM UTC+8, Sebastian Christ wrote:
    On 2016-04-12 22:34, Cai Gengyang <gengyangcai@gmail.com> wrote:
    What does "invoking the script without arguments" mean ?

    Are you sure that you've done all the exercises? You say you're now at Ex. 30,
    but obviously you didn't pay that much attention to Ex. 13, did you?

    Regards,
    Sebastian

    --
    Sebastian (Rudolfo) Christ
    http://rudolfochrist.github.io
    GPG Fingerprint: 306D 8FD3 DFB6 4E44 5061
    CE71 6407 D6F8 2AC5 55DD

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Klemme@21:1/5 to Cai Gengyang on Wed Apr 13 20:27:38 2016
    On 13.04.2016 18:08, Cai Gengyang wrote:
    Ok, it works now ! I was on exercise 15 (http://learnrubythehardway.org/book/ex15.html), not exercise 30 ...
    just named it ex30 randomly because I previously saved another file
    called ex15.

    That is still after exercise 13.

    CaiGengYangs-MacBook-Pro:GoatBoy CaiGengYang$ ruby ex30.rb ex30_sample.txt Here's your file ex30_sample.txt:
    This is stuff I typed into a file.
    It is really cool stuff.
    Lots and lots of fun to have in here.

    Type the filename again: ex30_sample.txt
    This is stuff I typed into a file.
    It is really cool stuff.
    Lots and lots of fun to have in here.

    I realised that I got the error because I initially forgot to create the 2nd sample.txt file

    That is wrong. You got the error because you did not pass an argument
    when invoking the script. You could also say that you got the error
    because your script did not deal well with invocation without arguments.

    Regards

    robert


    --
    remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cai Gengyang@21:1/5 to All on Thu Apr 14 21:59:40 2016
    Ok

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)