how to test the existence of a variable ruby code example Example: ruby check if exists apple = 1 defined?(apple) # "local-variable" defined?(bacon) # nil