As in this question, when a local variable not defined is used within its own assignment, it is evaluated to nil
.
x = x # => nil
I think in your case it's because it's what's expected :P
1.9.3-p194 :001 > {}.instance_eval{a=1}
=> 1
1.9.3-p194 :002 > {}.instance_eval{a}
NameError: undefined local variable or method `a' for {}:Hash
from (irb):2:in `block in irb_binding'
from (irb):2:in `instance_eval'
from (irb):2
from /Users/rafael/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `'
Instance eval evaluates code at instance level so each hash you are declaring is different. If you want to return keys this works
1.9.3-p194 :003 > {}.instance_eval{keys = self.keys
1.9.3-p194 :004?> keys = keys}
=> []