Package org.jruby

Examples of org.jruby.Ruby.newTypeError()


        RubyClass rubyClass;
       
        if (proxyClass instanceof RubyClass) {
            rubyClass = (RubyClass)proxyClass;
        } else {
            throw runtime.newTypeError(proxyClass, runtime.getModule());
        }

        Method jmethod = getMethodFromClass(runtime, proxyClass, name, argTypesClasses);
        String prettyName = name + CodegenUtils.prettyParams(argTypesClasses);
       
View Full Code Here


                bytes = (byte[])((JavaArray)byteArray).getValue();
            }
        }

        if (bytes == null) {
            throw runtime.newTypeError("wrong argument type " + wrappedObject.getMetaClass() +
                    " (expected byte[])");
        }

        return runtime.newString(new ByteList(bytes, true));
    }
View Full Code Here

   
    @JRubyMethod(module = true, visibility = Visibility.PRIVATE)
    public static IRubyObject ruby_string_to_bytes(IRubyObject recv, IRubyObject string) {
        Ruby runtime = recv.getRuntime();
        if (!(string instanceof RubyString)) {
            throw runtime.newTypeError(string, runtime.getString());
        }
        return JavaUtil.convertJavaToUsableRubyObject(runtime, ((RubyString)string).getBytes());
    }

    @JRubyMethod(module = true)
View Full Code Here

        String name = method.getName();
        Ruby runtime = context.runtime;
        RubyObject obj = (RubyObject) container.retrieve(context, self, currDynScope, temp);

        if (obj instanceof RubyFixnum || obj instanceof RubySymbol) {
            throw runtime.newTypeError("can't define singleton method \"" + name + "\" for " + obj.getMetaClass().getBaseName());
        }

        if (obj.isFrozen()) throw runtime.newFrozenError("object");

        RubyClass rubyClass = obj.getSingletonClass();
View Full Code Here

    // SSS FIXME: Is this code effectively equivalent to RuntimeHelpers.isJavaExceptionHandled?
    private boolean exceptionHandled(ThreadContext context, IRubyObject excType, Object excObj) {
        Ruby runtime = context.runtime;
        if (excObj instanceof IRubyObject) {
            // regular ruby exception
            if (!(excType instanceof RubyModule)) throw runtime.newTypeError("class or module required for rescue clause. Found: " + excType);
            return excType.callMethod(context, "===", (IRubyObject)excObj).isTrue();
        } else if (runtime.getException().op_ge(excType).isTrue() || runtime.getObject() == excType) {
            // convert java obj to a ruby object and try again
            return excType.callMethod(context, "===", JavaUtil.convertJavaToUsableRubyObject(runtime, excObj)).isTrue();
        } else if (excType instanceof RubyClass && excType.getInstanceVariables().hasInstanceVariable("@java_class")) {
View Full Code Here

        Object cmVal = currentModule.retrieve(context, self, currDynScope, temp);
        RubyModule module;
        if (cmVal instanceof RubyModule) {
            module = (RubyModule) cmVal;
        } else {
            throw runtime.newTypeError(cmVal + " is not a type/class");
        }
        Object constant = cachedConstant; // Store to temp so it does null out on us mid-stream
        if (!isCached(runtime, module, constant)) constant = cache(runtime, module);

        return constant;
View Full Code Here

        RubyModule module;

        if (cmVal instanceof RubyModule) {
            module = (RubyModule) cmVal;
        } else {
            throw runtime.newTypeError(cmVal + " is not a type/class");
        }

        SwitchPoint switchPoint = (SwitchPoint)runtime.getConstantInvalidator().getData();

        IRubyObject value = module.getConstantFromNoConstMissing(constName, false);
View Full Code Here

        String     name  = method.getName();

        // Error checks and warnings on method definitions
        Ruby runtime = context.runtime;
        if (clazz == runtime.getDummy()) {
            throw runtime.newTypeError("no class/module to add method");
        }

        if (clazz == runtime.getObject() && "initialize".equals(name)) {
            runtime.getWarnings().warn(ID.REDEFINING_DANGEROUS, "redefining Object#initialize may cause infinite loop");
        }
View Full Code Here

    @JRubyMethod(required = 1, optional = 1, visibility = Visibility.PRIVATE)
    public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
        Ruby runtime = context.getRuntime();
        if (this.vSource != null) {
            throw runtime.newTypeError("already initialized instance");
         }

        OptionsReader opts   = new OptionsReader(context, args.length > 1 ? args[1] : null);
        this.maxNesting      = opts.getInt("max_nesting", DEFAULT_MAX_NESTING);
        this.allowNaN        = opts.getBool("allow_nan", false);
View Full Code Here

    @JRubyMethod
    public IRubyObject initialize_copy(ThreadContext context, IRubyObject vOrig) {
        Ruby runtime = context.getRuntime();
        if (!(vOrig instanceof GeneratorState)) {
            throw runtime.newTypeError(vOrig, getType());
        }
        GeneratorState orig = (GeneratorState)vOrig;
        this.indent = orig.indent;
        this.space = orig.space;
        this.spaceBefore = orig.spaceBefore;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.