extern "C" int rb_ary_size(VALUE ary) { JLocalEnv env; int length = (int)(env->GetIntField(valueToObject(env, ary), RubyArray_length_field)); checkExceptions(env); return length; }
int RubyString::length() { // If already synced with java, just return the cached length value if (rwdata.rstring != NULL) { return rwdata.rstring->len; } JLocalEnv env; jobject byteList = env->GetObjectField(obj, RubyString_value_field); return env->GetIntField(byteList, ByteList_length_field); }
extern "C" ID rb_intern2(const char* name, long len) { std::map<StringKey, ID>::iterator it = nonConstSymbolMap.find(StringKey(name, len)); if (it != nonConstSymbolMap.end()) { return it->second; } JLocalEnv env; jobject result = env->CallObjectMethod(getRuntime(), Ruby_newSymbol_method, env->NewStringUTF(name)); checkExceptions(env); Symbol* sym = addSymbol(env, env->GetIntField(result, RubySymbol_id_field), result); nonConstSymbolMap.insert(std::map<StringKey, ID>::value_type(StringKey(sym->cstr, (long) len), sym->id)); return sym->id; }