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 ?
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/
What does "invoking the script without arguments" mean ?
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
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
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 293 |
Nodes: | 16 (2 / 14) |
Uptime: | 227:17:21 |
Calls: | 6,624 |
Calls today: | 6 |
Files: | 12,171 |
Messages: | 5,318,848 |