Marty the Robot – Programmable walking robot for kids
indiegogo.com32 pointsby nottombrown15 comments
extension Optional {
func try<U>(f: (T) -> U) -> Optional<U> {
if let unwrapped = self {
return f(unwrapped)
} else {
return nil
}
}
}
You can see how to use it in this gist: 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 favorite dinosaur is #{user.dino})"
else
p "No user. (Let's assume she likes T-rexs)"
end
end
possible_user = User.find_by_favorite_dinosaur("Dromiceiomimus")
print_favorite_dinosaur(possible_user) def try(*a, &b)
if a.empty? && block_given?
yield self
else
public_send(*a, &b) if respond_to?(a.first)
end
end
https://github.com/rails/rails/blob/d68419a88e424e588c2d8dec...
Many other readers were confused by this so we'll update the formatting to say "target completion" to make this more clear.