public static void checkNameAvailability(ThreadContext context, String name) { if (context.runtime.getObject().getConstantAt(name) != null) throw context.runtime.newNameError(name + " is already defined", name); }
@Override public IRubyObject set(IRubyObject lastExitStatus) { throw runtime.newNameError("$? is a read-only variable", "$?"); } }
/** * @see Ruby#newNameError(String, IRubyObject, IRubyObject, boolean) */ public RaiseException newNameError(String message, IRubyObject recv, IRubyObject name) { return newNameError(message, recv, name, false); }
/** * Construct a NameError that formats its message with an sprintf format string. * * This version just accepts a java.lang.String for the name. * * @see Ruby#newNameError(String, IRubyObject, IRubyObject) */ public RaiseException newNameError(String message, IRubyObject recv, String name) { return newNameError(message, recv, name, false); }
/** * Construct a NameError that formats its message with an sprintf format string and has private_call? set to given. * * This version just accepts a java.lang.String for the name. * * @see Ruby#newNameError(String, IRubyObject, IRubyObject) */ public RaiseException newNameError(String message, IRubyObject recv, String name, boolean privateCall) { RubySymbol nameSym = newSymbol(name); return newNameError(message, recv, nameSym, privateCall); }
/** * Checks if the name parameter represents a legal instance variable name, and otherwise throws a Ruby NameError */ @Deprecated protected String validateInstanceVariable(String name) { if (IdUtil.isValidInstanceVariableName(name)) return name; throw getRuntime().newNameError("`%1$s' is not allowable as an instance variable name", this, name); }
protected final String validateClassVariable(IRubyObject nameObj, String name) { if (IdUtil.isValidClassVariableName(name)) { return name; } throw getRuntime().newNameError("`%1$s' is not allowed as a class variable name", this, nameObj); }
@JRubyMethod(required = 1, visibility = PRIVATE) public IRubyObject initialize_copy(ThreadContext context, IRubyObject original) { if (this.isInited) { throw context.runtime.newNameError("`initialize' called twice", "initialize"); } RubyRange other = (RubyRange) original; init(context, other.begin, other.end, other.isExclusive); return context.nil; }
protected final String validateClassVariable(String name) { if (IdUtil.isValidClassVariableName(name)) { return name; } throw getRuntime().newNameError("`%1$s' is not allowed as a class variable name", this, name); }
@Override public IRubyObject set(IRubyObject value) { throw runtime.newNameError(name() + " is a read-only variable", name()); } }
@Deprecated // no-longer used public static JavaMethod createDeclared(Ruby runtime, Class<?> javaClass, String methodName, Class<?>[] argumentTypes) { try { return create(runtime, javaClass.getDeclaredMethod(methodName, argumentTypes)); } catch (NoSuchMethodException e) { throw runtime.newNameError(undefinedMethodMessage(runtime, ids(runtime, methodName), ids(runtime, javaClass.getName()), false), methodName); } }
@Override // skip constant name assert public final IRubyObject fetchConstant(String name, boolean includePrivate) { ConstantEntry entry = constantEntryFetch(name); if (entry == null) return null; if (entry.hidden && !includePrivate) { throw getRuntime().newNameError("private constant " + getName() + "::" + name + " referenced", name); } return entry.value; }
/** rb_define_const * */ @Extension public void defineConstant(String name, IRubyObject value) { assert value != null; if (!IdUtil.isValidConstantName(name)) { throw getRuntime().newNameError("bad constant name " + name, name); } setConstant(name, value); }
@JRubyMethod(required = 2, optional = 1, visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block unusedBlock) { if (this.isInited) { throw context.runtime.newNameError("`initialize' called twice", "initialize"); } checkFrozen(); init(context, args[0], args[1], args.length > 2 && args[2].isTrue()); return context.nil; }
@JRubyMethod public IRubyObject local_variable_get(ThreadContext context, IRubyObject symbol) { String name = symbol.asJavaString().intern(); DynamicScope evalScope = binding.getEvalScope(context.runtime); int slot = evalScope.getStaticScope().isDefined(name); if (slot == -1) throw context.runtime.newNameError("local variable `" + name + "' not defined for " + inspect(), name); return evalScope.getValueOrNil(slot & 0xffff, slot >> 16, context.nil); }
@JRubyMethod(name="read_object", alias="readObject") public IRubyObject readObject() { try { return Java.getInstance(getRuntime(), impl.readObject()); } catch (IOException ioe) { throw getRuntime().newIOErrorFromException(ioe); } catch (ClassNotFoundException cnfe) { throw getRuntime().newNameError(cnfe.getLocalizedMessage(), cnfe.getMessage(), cnfe); } }
private RubyBoolean constantDefined(Ruby runtime, RubySymbol symbol, boolean inherit) { if (symbol.validConstantName()) { return runtime.newBoolean(getConstantSkipAutoload(symbol.idString(), inherit, inherit) != null); } throw runtime.newNameError(str(runtime, "wrong constant name", ids(runtime, symbol)), symbol.idString()); }
/** * Validates name is a valid constant name and returns its id string. * @param name object to verify as a valid constant. * @return the id for this valid constant name. */ protected final String validateConstant(IRubyObject name) { RubySymbol symbol = RubySymbol.retrieveIDSymbol(name); if (!symbol.validConstantName()) { throw getRuntime().newNameError(str(getRuntime(), "wrong constant name ", name), symbol.idString()); } return symbol.idString(); }
private DynamicMethod deepMethodSearch(String id, Ruby runtime) { DynamicMethod method = searchMethod(id); if (method.isUndefined() && isModule()) method = runtime.getObject().searchMethod(id); if (method.isUndefined()) { RubySymbol name = runtime.newSymbol(id); throw runtime.newNameError(undefinedMethodMessage(runtime, name, rubyName(), isModule()), id); } return method; }
private DynamicMethod deepMethodSearch(String id, Ruby runtime) { DynamicMethod method = searchMethod(id); if (method.isUndefined() && isModule()) method = runtime.getObject().searchMethod(id); if (method.isUndefined()) { RubySymbol name = runtime.newSymbol(id); throw runtime.newNameError(undefinedMethodMessage(runtime, name, rubyName(), isModule()), id); } return method; }