Recall & Review
beginner
What keyword is used to declare a method in Ruby?
The keyword
def is used to declare a method in Ruby.Click to reveal answer
beginner
How do you end a method declaration in Ruby?
You end a method declaration with the keyword
end.Click to reveal answer
beginner
What is the correct way to declare a method named
greet that prints 'Hello'?Use:<br>
def greet puts 'Hello' end
Click to reveal answer
intermediate
Can Ruby methods return values? How?
Yes, Ruby methods return the value of the last executed expression automatically.
Click to reveal answer
intermediate
What happens if you call a method without parentheses in Ruby?
Ruby allows calling methods without parentheses if there are no arguments, making code look cleaner.
Click to reveal answer
Which keyword starts a method declaration in Ruby?
✗ Incorrect
In Ruby,
def is the keyword used to start a method declaration.How do you end a method declaration in Ruby?
✗ Incorrect
Ruby uses the keyword
end to close blocks including method declarations.What will this Ruby method return?<br>
def add 2 + 3 end
✗ Incorrect
Ruby methods return the last evaluated expression automatically, so this returns 5.
Which of these is a valid method call in Ruby?
✗ Incorrect
Ruby allows calling methods with or without parentheses if there are no arguments.
What is the output of this code?<br>
def say_hi puts 'Hi!' end say_hi
✗ Incorrect
The method prints 'Hi!' to the screen when called.
Explain how to declare a simple method in Ruby using
def and end.Think about the start and end keywords and what goes in between.
You got /4 concepts.
Describe how Ruby methods return values and how you can call them.
Remember Ruby's automatic return and flexible syntax.
You got /3 concepts.