Method: Oj::Doc#local_key

Defined in:
ext/oj/fast.c

#local_keyObject

Returns the final key to the current location. “one” Oj::Doc.open(‘‘) { |doc| doc.local_key() } #=> nil

Examples:

Oj::Doc.open('[1,2,3]') { |doc| doc.move('/2'); doc.local_key() } #=> 2
Oj::Doc.open('{"one":3}') { |doc| doc.move('/one'); doc.local_key() }  #=>


1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
# File 'ext/oj/fast.c', line 1252

static VALUE doc_local_key(VALUE self) {
    Doc            doc  = self_doc(self);
    Leaf           leaf = *doc->where;
    volatile VALUE key  = Qnil;

    if (T_HASH == leaf->parent_type) {
        key = rb_utf8_str_new_cstr(leaf->key);
    } else if (T_ARRAY == leaf->parent_type) {
        key = LONG2NUM(leaf->index);
    }
    return key;
}