def METHOD_NAME(self, ref, type=None):
    '''
    Look up a symbol in the current context.
    The caller is expected to provide a list of stems of a qualified
    reference as `ref`. That is, to look up the qualified reference
    'foo.bar.baz', the caller would provide `ref` as ['foo', 'bar', 'baz'].
    The values returned can be filtered by type using the optional `type`
    argument.
    '''
    assert isinstance(ref, list) and len(ref) > 0 and \
        all([isinstance(x, six.string_types) for x in ref])
    # Peel off the root stem.
    head, tail = ref[0], ref[1:]
    # Look backwards through the scopes to ensure we yield inner results
    # before outer results.
    for scope in reversed(self.scopes):
        for candidate in scope[head].values():
            if len(tail) == 0:
                # Bottomed out resolution of the full reference.
                if type is None or isinstance(candidate, type):
                    yield candidate
            else:
                # Construct a scope for the entity we've found and
                # continue the search, descending into it.
                inner = within(candidate)
                for c in inner.METHOD_NAME(tail, type):
                    if type is None or isinstance(c, type):
                        yield c