Is it possible to define a method
a = 123
if defined? a
puts a? # false
In ruby, the keyword
def acts a scope gate, so you lose access to local variables that are defined outside of the method definition. Alternatively, you can define methods using a block, allowing you access to variables defined outside of the method definition.
a = '123' define_method 'a?' do defined? a end
For more information on this, I highly recommend reading through the first section of Metaprogramming Ruby