+ 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
1 Resposta
+ 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)