Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Basics Ruby Syntax Method Arguments

Pui Lun Christin C Hebron
Pui Lun Christin C Hebron
5,693 Points

Define a method named say. The say method should take one parameter (name the parameter whatever you want). In the say m

This is my answer, not sure why it's not working

Define a method named say. The say method should take one parameter (name the parameter whatever you want). In the say method body, take the parameter and pass it to puts as an argument. End your program with a call to the say method, and pass the string "Ruby" as an argument.

def say(ruby) puts(ruby) end

say(hi)

say.rb
def say(ruby)
  puts(ruby)
end

say(hi)

5 Answers

Brandon Williams
Brandon Williams
6,933 Points

None of the terms were making any sense to me so I went back and rewatched the previous video.

This is what I tried, it made no sense to me, but it worked to pass the challenge.

def say(whatever)
   puts whatever
end

say("Ruby")

I guess I'm not understanding the point in listing "whatever" and "puts whatever" only to never define it as "Ruby". Seems like you would define whatever as "Ruby" [like whatever = "Ruby"] but you never do that so I don't understand it.

Steven Parker
Steven Parker
231,268 Points

This may just be one of those things you "get" after a bit more practice. The more realistic examples you'll see in later exercises may help also.

Steven Parker
Steven Parker
231,268 Points

The error message gives you a clue: "Bummer: undefined local variable or method `hi' for main:Object". Since "hi" is not enclosed in quotes, it is taken to be an identifier but nothing by that name has been defined.

But the instructions say to "pass the string "Ruby" as an argument.", so that's what should be there anyway.

Brandon Williams
Brandon Williams
6,933 Points

I can't get this to work either. This is what I wrote:

def say(Chuck_Norris)
  puts "Ruby"
end

Chuck_Norris
Steven Parker
Steven Parker
231,268 Points

Always start a fresh question instead of posting one as an "answer" to another question.

But there's a few issues here:

  • the argument given to "puts" should be enclosed in parentheses
  • that argument should be the same as the parameter name of your function
  • the call on the last line must reference the function by name ("say")
  • the argument to the call must be enclosed in parentheses
  • the instructions ask for that argument to be "Ruby"
Brandon Williams
Brandon Williams
6,933 Points

I posted it as a new topic also, was hoping maybe one of these students could chime in with what worked for them (hopefully they didn't give up).

Brandon Williams
Brandon Williams
6,933 Points

Couldn't get this to work either.

def say("Ruby")
  puts ("Ruby")
end

("say")
Steven Parker
Steven Parker
231,268 Points

You've missed a few of the hints I gave previously. Also:

  • argument and parameter names cannot be enclosed in quotes (actual arguments can)
  • a function name also cannot be enclosed in quotes
  • when being called, a function name should be followed (but not enclosed) by parentheses

If you still have trouble, please follow my original suggestion and start a new, fresh question.