Ruby - Methods
What will be the output of the following Ruby code?
def greet(*names)
names.join(", ")
end
puts greet("Alice", "Bob", "Carol")def greet(*names)
names.join(", ")
end
puts greet("Alice", "Bob", "Carol")*names worksnames. Here, it will be ["Alice", "Bob", "Carol"].names.join(", ") joins array elements into a string separated by ", ". So the output is "Alice, Bob, Carol".15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions