Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Basics (Retired) How Ruby Works Hello World!

Rahul Nayak
Rahul Nayak
1,221 Points

Error while running hello.rb

So here is my code which I tried running: name="Rahul" puts "Hello" puts name

I have written the above code in a file named hello.rb and here is the error output I received :

treehouse:~/workspace$ irb
irb(main):001:0> ruby hello.rb
NameError: undefined local variable or method hello' for main:Object from (irb):1 from /usr/local/bin/irb:11:in<main>'

Where am I going wrong ?

4 Answers

You don't want to enter irb first. You can either do irb hello.rb or ruby hello.rb in the commend line.

Rahul Nayak
Rahul Nayak
1,221 Points

Thanks a lot. And I was wondering if I am that stupid that even the simplest of code is giving me an error!!

All you need to do is enter ruby hello.rb. No need to enter IRB. The reason you are receiving the error message is because you are running something from IRB and what you are running has not been defined.

Hi rahul, so this is where you are going wrong: '''puts "Hello" puts name'''

1) you have 2 puts when you only need 1 puts to print Hello and your name 2) in order to print the Hello string and the variable name you need to concatenate both with a + sign

make sense?

Rahul, Donald is right on with the issue here. Follow this step