Is this different than setting a default value of nil to user? def print_favorite_dinosaur(user: nil) or def print_favorite_dinosaur(user = nil) Or is it effectively a different syntax for the same concept? In either language, you still signal that the argument could be nil, and you still have to guard against it. Or so I think
In Swift, you have to signal and guard against the nil. In ruby, you choose whether to signal and you choose whether to guard. Here are some ruby examples that may be more clear: Does not signal user = User.find_by_favorite_dinosaur("Dromiceiomimus") Does not guard def print_favorite_dinosaur(user) p "User's favorite dinosaur is #{user.dino})" end Signals and guards def print_favorite_dinosaur(user) if user p "User's…
Re: Swift for Rubyists: Optionals
#11Thanks, I didn't know that swift requires the optional to be guarded against.