In Ruby I defined these on Object. A little ugly if you are doing a long chain, but works fine in many cases.
def if_present?
# example: User.find_all_by_something.if_present? || User.find_all_by_something_else
self if present?
end
def send_if_respond_to(method, *args)
# example: string_or_nil.send_if_respond_to(:strip)
send(method, *args) if respond_to?(method)
end