Chris came up with this excellent little snippet, try, as seen on Ruby Inside.
That inspired me to a create a similarly sugary method for an idiom I use time and again:
class Object
##
# @person.name rescue nil
# vs
# @person.do_or_do_not(:name)
def do_or_do_not(method)
send method rescue nil
end
end
Comments