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

Nadia Masiero
Nadia Masiero
3,468 Points

Defining a Method in Ruby

Define a method named say. say 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. Then it says "Bummer! We couldn't find a method named "say". Did you define one?" I don't know what I'm doing wrong here.

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

1 Answer

Samuel Ferree
Samuel Ferree
31,722 Points

in ruby, starting your variable with a capital letter makes it a constant, and constant variables can't be passed into functions/methods. without going to much into detail, always define ruby variables with a lower case letter first.

Additionally, in your method call at the end, you're passing the constant Ruby into the method. which probably isn't defined. I don't think you need to call your method to complete the challenge, but I've included it below.

def say(ruby) #lowercase 
  puts(ruby) #lowercase
end
say("Hello")
Nadia Masiero
Nadia Masiero
3,468 Points

Thank you!!! I didn't realize that constant variables couldn't be passed like that. Thank you so much!!!