this could be two lines:

raise NoAttributeError... unless a.has_key?(part)

a = a[part]

or even if you don't like that trailing line:

if ! a.has_key?(part)
  raise
end

a = a[part]