Help! Undefined local variable

A

Anthony Ob

p009mymethods1.rb:11: undefined local variable or method 'mtd' for
main"object <NameError>

=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
http://rubylearning.com/satishtalim/writing_own_ruby_methods.html
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

Haha, thank you!

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top