George Qoridze
George Qoridze

Reputation: 69

The Debugging Primaries

I'm doing the "8.1 The Debugging Primaries". One of the exercises asks me to:

fix the method so that it prints the name and age from the parameter I pass to it.

The exercise looks like this:

def describe(user_info)
  "My name is #{user_info[0]} and I'm #{user_info[1]} years old."
end

there is a hint below the exercise:

Do a p on the user_info and look at what parameter I'm passing to it.

I wrote the statement p user_info and a @ sign before the parameter in the method:

def describe(user_info)
  "My name is #{@user_info[0]} and I'm #{@user_info[1]} years old."
end

p user_info

but received an error.

Can anyone tell me how to do to get the positive result and please explain what is the meaning of the square brackets after the parameter?

Upvotes: 2

Views: 218

Answers (2)

Kirill Husiatyn
Kirill Husiatyn

Reputation: 828

I solved this problem in this way:

def describe(user_info)
  p "My name is #{user_info["name"]} and I'm #{user_info["age"]} years old."
end

Please, read errors =)

Upvotes: 1

mirelon
mirelon

Reputation: 4996

The error is:

class: NameError
message: undefined local variable or method `user_info' for main:Object
backtrace: RubyMonk:8:in `<top (required)>'

user_info is a local variable defined in the scope of method describe. As stated in the error message, it is not defined outside the method. Move the instruction p user_info inside the method.

Upvotes: 0

Related Questions