When there are default values for both parameters but there is only one argument provided, how do i know which parameter it it means to feed? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

When there are default values for both parameters but there is only one argument provided, how do i know which parameter it it means to feed?

7th Feb 2017, 4:21 PM
yuxme
2 Answers
+ 7
Left to right :)
7th Feb 2017, 4:26 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
Agreed, but it is worth noting that since parameters are positional, that it is the comma separating the parameters that will determine which position within parameter list uses the default value or the passed value. Consider the following code (EOE violations aside): def goodCandidate (name="", age=21, gender="boy") if age>21 && gender=="boy" puts "#{name}, you're hired!" else puts "Sorry #{name}. The position is filled." end end goodCandidate "Sally", 17, "girl" puts "====" goodCandidate "Bill", 43 ----------------------------------- How would you use the default value for 'age' if you supplied values for 'name' and 'gender'?
11th Feb 2017, 12:52 PM
Mike L.
Mike L. - avatar