+ 2

Ruby method - How Fill the blanks to create a method that takes optional parameters and outputs the squares of its parameters:

Fill in the blanks to create a method that takes optional parameters and outputs the squares of its parameters: def sq(_p) __.each {|_| puts x*x} end

11th May 2020, 8:54 PM
Андрей Рыбаков
Андрей Рыбаков - avatar
1 Réponse
+ 1
You can use the asterix (*) in front of a parameter name to get an array of values. def sq(*p) p.each {|x| puts x*x} end sq(3, 5.6, 42)
11th May 2020, 9:38 PM
Manu_1-9-8-5
Manu_1-9-8-5 - avatar