There are minimu two ways. First - by using defined? method:
if defined? my_var puts "exists" else puts "doesn't exist" end
defined? method returns type of variable if variable exists and nil otherwise. Second way is by initializing variable which you want to check ...
my_var = nil if my_var.nil? #logic goes here else #otherwise end