Ruby Ruby Basics Ruby Syntax Defining Methods

Shaun Lennon
Shaun Lennon
Full Stack JavaScript Techdegree Student 2,767 Points

How do I define a method called say_hi?

Define a method named say_hi. The method body should include a call to puts with an argument of "hi". Then call your new say_hi method.

def say_hi
  puts "hi"

1 Answer

Steven Parker
Steven Parker
194,932 Points

The definition of the method is OK. But when the instructions asked "then call the method", they meant do it after the definition (after the "end").

Doing it inside causes it to call itself over and over (known as a "recursion loop") and creates an error.