Learn Ruby The Hard Way --- Exercise 1

Hello,

So I am going through Michael Hartl’s “Learn Ruby The Hard Way”, managed to complete exercise 0 successfully , learned how to install a text editor , run the text editor and run the Terminal.

Currently, I am stuck on Exercise 1 -----------------------------------------------------------------------------

I typed the following text into a single TextWrangler file named ex1.rb (created a folder in my home directory called ex1.rb and saved it) ---------------------------------------------------------------------------

puts “Hello World!”
puts “Hello Again”
puts “I like typing this.”
puts “This is fun.”
puts “Yay! Printing.”
puts “I’d much rather you ‘not’.”
puts ‘I “said” do not touch this.’

When I tried to run the file in my Terminal, I got error messages though -----------------------------------

CaiGengYangs-MacBook-Pro:~ CaiGengYang$ ruby ex1.rb
ruby: No such file or directory – ex1.rb (LoadError)
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ ruby ex1.rb
ruby: No such file or directory – ex1.rb (LoadError)
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ ruby ex1.rb
ruby: No such file or directory – ex1.rb (LoadError)
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ ruby ex1.rb
ruby: No such file or directory – ex1.rb (LoadError)
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ ruby ex1.rb
ruby: No such file or directory – ex1.rb (LoadError)
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ ruby ex1.rb
ruby: Is a directory – ex1.rb (LoadError)
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ ruby ex1.rb
ruby: Is a directory – ex1.rb (LoadError)
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ ex1.rb
-bash: ex1.rb: command not found
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ ruby ex1.rb
ruby: Is a directory – ex1.rb (LoadError)
CaiGengYangs-MacBook-Pro:~ CaiGengYang$

Doesn’t seem to work whatever I do … Any help appreciated , thanks alot.

Gengyang

This is the link to the instructions in exercise 1 --------- http://learnrubythehardway.org/book/ex1.html

You need to have the file saved in the same directory that you run ruby ex1.rb from.

Perhaps you’ve named the folder what the file should be named?

Yea, I created a folder in my home directory called ex1.rb and saved the file in it … doesn’t seem to work though weird

Did you change directory to your ~/mystuff directory?

$> cd ~/mystuff
$> ruby ex1.rb

Guess it works now : This is my output

CaiGengYangs-MacBook-Pro:mystuff CaiGengYang$ cd ~/mystuff
CaiGengYangs-MacBook-Pro:mystuff CaiGengYang$ ruby ex1.rb
Hello World!
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I’d much rather you ‘not’.
I “said” do not touch this.
CaiGengYangs-MacBook-Pro:mystuff CaiGengYang$