I\'m playing with Ruby on Rails and I\'m trying to create a method with optional parameters. Apparently there are many ways to do it. I trying naming the optional parameters
To answer the question of "why?": the way you're calling your function,
my_info "Bill", age: 99, weight: 300, city: "Sao Paulo"
is actually doing
my_info "Bill", {:age => 99, :weight => 300, :city => "Sao Paulo"}
Notice you are passing two parameters, "Bill" and a hash object, which will cause the default hash value you've provided in my_info2 to be completely ignored.
You should use the default value approach that the other answerers have mentioned.