Hash.new with block logic
p h = Hash.new { |hash, key| (key.respond_to? :to_str) ? "nope" : nil } p h[1] # => nil p h['do'] # => "nope"