Why not single line?

( unshell("ip route show dev #{device}") rescue nil ) || ""