# Help! Undefined local variable

**URL:** <https://www.ruby-forum.com/t/help-undefined-local-variable/195615>\
**Category:** Ruby\
**Created:** [September 26, 2010, 11:31pm UTC](https://www.ruby-forum.com/t/help-undefined-local-variable/195615 "2010-09-26T23:31:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthonyob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a3d4f5/32.png) [@anthonyob](https://www.ruby-forum.com/u/anthonyob)\
**Post date:** [September 26, 2010, 11:31pm UTC](https://www.ruby-forum.com/t/help-undefined-local-variable/195615/1 "2010-09-26T23:31:55Z")

</div>

p009mymethods1.rb:11: undefined local variable or method ‘mtd’ for  
main"object

=begin  
p008mymethods1.rb  
interpolation refers to the process of inserting the result of  
an expression into a string literal  
the interpolation operator #(…) gets calculated seperately  
=end

def mtf(arg1=“Dibya”, arg2=“Shashank”, arg3=“shashank”)  
“#{arg1}, #{arg2}, #{arg3}.”  
end  
puts mtd  
puts mtd(“ruby”)

Thats my whole ruby code from a tutorial

> **[Learn How to Blog and Build Websites for Profit!](https://heyblogging.com)**
>
> Ready to take your blogging skills to the next level? Learn how to build a website that generates income and sets you up for success.

---

<div class="post-metadata">

**Author:** ![anthonyob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a3d4f5/32.png) [@anthonyob](https://www.ruby-forum.com/u/anthonyob)\
**Post date:** [September 26, 2010, 11:45pm UTC](https://www.ruby-forum.com/t/help-undefined-local-variable/195615/2 "2010-09-26T23:45:24Z")

</div>

Anthony,

On 26.09.2010 23:32, Anthony Ob wrote:

> def mtf(arg1=“Dibya”, arg2=“Shashank”, arg3=“shashank”)

You miss-typed here: should be “mtd”.

> “#{arg1}, #{arg2}, #{arg3}.”  
> end  
> puts mtd  
> puts mtd(“ruby”)

- Markus

---

<div class="post-metadata">

**Author:** ![anthonyob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a3d4f5/32.png) [@anthonyob](https://www.ruby-forum.com/u/anthonyob)\
**Post date:** [September 26, 2010, 11:53pm UTC](https://www.ruby-forum.com/t/help-undefined-local-variable/195615/3 "2010-09-26T23:53:06Z")

</div>

Markus F. wrote:

> Anthony,
> 
> On 26.09.2010 23:32, Anthony Ob wrote:
> 
> > def mtf(arg1=“Dibya”, arg2=“Shashank”, arg3=“shashank”)
> 
> You miss-typed here: should be “mtd”.
> 
> > “#{arg1}, #{arg2}, #{arg3}.”  
> > end  
> > puts mtd  
> > puts mtd(“ruby”)
> 
> - Markus

Haha, thank you!

---

<div class="post-metadata">

**Author:** ![anthonyob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a3d4f5/32.png) [@anthonyob](https://www.ruby-forum.com/u/anthonyob)\
**Post date:** [September 27, 2010, 1:41am UTC](https://www.ruby-forum.com/t/help-undefined-local-variable/195615/4 "2010-09-27T01:41:20Z")

</div>

On Sun, Sep 26, 2010 at 4:53 PM, Anthony Ob [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > puts mtd  
> > > puts mtd(“ruby”)
> > 
> > - Markus
> 
> ## Haha, thank you!
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

The error is telling you that. You asked it to call the method mtd, it  
says  
“undefined local variable or method ‘mtd’” but you know it exists right  
there, since you just wrote it. So you should be asking yourself why it  
can’t find the method that you can see. Misspelled names are the most  
common  
cause of this. Second most common is probably accidentally defining an  
instance method instead of a class method.

Try to pay attention when things like this happen. See what it says,  
think  
about why it says that and what could be the causes. Take note of the  
solution. After a while, this will help you develop an intuition for  
resolving issues like this.
