Help! Undefined local variable

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

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

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!

On Sun, Sep 26, 2010 at 4:53 PM, Anthony Ob [email protected]
wrote:

puts mtd
puts mtd(“ruby”)

  • Markus

Haha, thank you!

Posted via 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs