Complete the code to explicitly return the sum of two numbers.
def add(a, b) [1] a + b end
The return keyword explicitly sends the result back from the method.
Complete the code to explicitly return the string 'Hello' from the method.
def greet [1] "Hello" end
The return keyword explicitly returns the string from the method.
Fix the error in the method to explicitly return the product of two numbers.
def multiply(x, y) product = x * y [1] product end
Using return explicitly sends the product back from the method.
Fill both blanks to explicitly return the length of the string if it is greater than 5.
def check_length(str) if str.length > 5 [1] str.length else [2] 0 end end
Both branches use return to explicitly send back a value from the method.
Fill all three blanks to explicitly return a hash with keys as uppercase letters and values as their lengths for words longer than 3 letters.
def word_lengths(words) result = {} words.each do |word| if word.length > 3 result[[1]] = [2] [3] result end end result end
The method returns a hash where keys are uppercase words and values are their lengths. The return keyword explicitly returns the hash inside the loop.