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?
2 ответов
+ 7
Left to right :)
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'?