# NameError: undefined local variable or method \`testapp' for main:Object

**URL:** <https://www.ruby-forum.com/t/nameerror-undefined-local-variable-or-method-testapp-for-main-object/174702>\
**Category:** Rails\
**Created:** [August 31, 2009, 6:06pm UTC](https://www.ruby-forum.com/t/nameerror-undefined-local-variable-or-method-testapp-for-main-object/174702 "2009-08-31T18:06:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@maddy](https://www.ruby-forum.com/u/maddy)\
**Post date:** [August 31, 2009, 6:06pm UTC](https://www.ruby-forum.com/t/nameerror-undefined-local-variable-or-method-testapp-for-main-object/174702/1 "2009-08-31T18:06:25Z")

</div>

Hi,

I am new to Ruby on Rails. Recently, I downloaded and installed the  
InstantRails in the D:\ drive of my system. Now I wanted to try some  
small examples in ‘irb’, so I created a file “testapp.rb” and in that  
pasted a code like this:

========================  
class sample\_class  
def sample\_method  
puts “sample program”  
end  
end

# myclass = sample\_class.new myclass.sample\_method

Now when I give command (To run the application) “ruby testapp.rb” ,  
I get this error “NameError: undefined local variable or method  
`testapp’ for main:Object”. I believe, the irb is not able to  
recognize any .rb file. Can anybody help me with this?

Additional details:-

location of irb - D:\RoR\ruby\bin  
location of testapp.rb - D:\RoR\ruby\bin

Many thanks in advance!

---

<div class="post-metadata">

**Author:** ![maddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@maddy](https://www.ruby-forum.com/u/maddy)\
**Post date:** [August 31, 2009, 6:07pm UTC](https://www.ruby-forum.com/t/nameerror-undefined-local-variable-or-method-testapp-for-main-object/174702/2 "2009-08-31T18:07:00Z")

</div>

On Aug 31, 3:43 pm, maddy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Now when I give command (To run the application) “ruby testapp.rb” ,  
> I get this error “NameError: undefined local variable or method  
> `testapp’ for main:Object”. I believe, the irb is not able to  
> recognize any .rb file. Can anybody help me with this?

You are mixing things up a bit. ruby testapp.rb is what you’d enter at  
the command prompt to run a ruby script. irb on the other hand is a  
ruby console, that evaluates ruby code.

Fred

---

<div class="post-metadata">

**Author:** ![maddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@maddy](https://www.ruby-forum.com/u/maddy)\
**Post date:** [August 31, 2009, 7:25pm UTC](https://www.ruby-forum.com/t/nameerror-undefined-local-variable-or-method-testapp-for-main-object/174702/3 "2009-08-31T19:25:27Z")

</div>

Hi Fred,

Thanks for clarification. You’re right, I had mixed up things  
there.

Thanks,  
Maddy

On Aug 31, 9:05 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![maddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@maddy](https://www.ruby-forum.com/u/maddy)\
**Post date:** [August 31, 2009, 10:02pm UTC](https://www.ruby-forum.com/t/nameerror-undefined-local-variable-or-method-testapp-for-main-object/174702/4 "2009-08-31T22:02:55Z")

</div>

ruby class names are Upper case by definition, use:

class Sampleclass  
or  
class SampleClass
