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,710 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!!!