Ruby has this defined? keyword that helps you check if a Variable is defined or not. If the variable exists you’ll get its type: apple = 1 defined?(apple) # "local-variable" If it doesn’t you’ll get nil: defined?(bacon) # nil This is like Javascript’s typeof operator. If you want to know the class of an object […]
The post How to Check If a Variable is Defined in Ruby appeared first on RubyGuides. Don't miss your free gift here :)