Package org.jruby

Examples of org.jruby.RubyClass$VariableAccessorField


@JRubyClass(name="Net::BufferedIO")
public class NetProtocolBufferedIO {
    public static void create(Ruby runtime) {
        RubyModule mNet = runtime.getModule("Net");

        RubyClass cBufferedIO = (RubyClass)mNet.getConstant("BufferedIO");
        cBufferedIO.defineAnnotatedMethods(NetProtocolBufferedIO.class);

        RubyModule mNativeImpl = cBufferedIO.defineModuleUnder("NativeImplementation");

        mNativeImpl.defineAnnotatedMethods(NativeImpl.class);
    }   
View Full Code Here


                if(n > 0) {
                    IRubyObject readItems = io.read(new IRubyObject[]{recv.getRuntime().newFixnum(1024*16)});
                    return buf.concat(readItems);
                } else {
                    RubyClass exc = (RubyClass)(recv.getRuntime().getModule("Timeout").getConstant("Error"));
                    throw new RaiseException(RubyException.newException(recv.getRuntime(), exc, "execution expired"),false);
                }
            } catch(IOException exception) {
                throw recv.getRuntime().newIOErrorFromException(exception);
            } finally {
View Full Code Here

      public IRubyObject allocate(Ruby runtime, RubyClass klass) {
    return new JRubyObjectInputStream(runtime, klass);
        }
    };
    public static RubyClass createJRubyObjectInputStream(Ruby runtime) {
  RubyClass result = runtime.defineClass("JRubyObjectInputStream",runtime.getObject(),JROIS_ALLOCATOR);
  result.defineAnnotatedMethods(JRubyObjectInputStream.class);
  return result;
    }
View Full Code Here

   
    public static class WeakRefLibrary implements Library {
        public void load(Ruby runtime, boolean wrap) throws IOException {
            RubyKernel.require(runtime.getKernel(), runtime.newString("delegate"), Block.NULL_BLOCK);
           
            RubyClass delegatorClass = (RubyClass)runtime.getClassFromPath("Delegator");
            RubyClass weakrefClass = runtime.defineClass("WeakRef", delegatorClass, WEAKREF_ALLOCATOR);
           
            weakrefClass.defineAnnotatedMethods(WeakRef.class);
           
            runtime.defineClass("RefError", runtime.getStandardError(), runtime.getStandardError().getAllocator());
        }
View Full Code Here

        }

        if (rubyObject instanceof RubyProc) {
            // Proc implementing an interface, pull in the catch-all code that lets the proc get invoked
            // no matter what method is called on the interface
            RubyClass singletonClass = rubyObject.getSingletonClass();

            singletonClass.addMethod("method_missing", new DynamicMethod(singletonClass, Visibility.PUBLIC, CallConfiguration.NO_FRAME_NO_SCOPE) {

                @Override
                public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
                    if (!(self instanceof RubyProc)) {
                        throw context.getRuntime().newTypeError("interface impl method_missing for block used with non-Proc object");
View Full Code Here

                objClass = (RubyClass)runtime.fastGetModule("YAML").fastGetConstant("Object");
                final RubyHash vars = (RubyHash)(((JRubyConstructor)ctor).constructRubyMapping(node));
                return RuntimeHelpers.invoke(runtime.getCurrentContext(), objClass, "new", runtime.newString(tag), vars);
            }
        }
        final RubyClass theCls = (RubyClass)objClass;
        final RubyObject oo = (RubyObject)theCls.getAllocator().allocate(runtime, theCls);
        final Map vars = (Map)(ctor.constructMapping(node));
        ctor.doRecursionFix(node, oo);
        for(final Iterator iter = vars.keySet().iterator();iter.hasNext();) {
            final IRubyObject key = (IRubyObject)iter.next();
            final Object val = vars.get(key);
View Full Code Here

    }

    public static Object constructRubyStruct(final Constructor ctor, final String tag, final Node node) {
        final Ruby runtime = ((JRubyConstructor)ctor).runtime;
        RubyModule sClass = runtime.fastGetModule("Struct");
        RubyClass struct_type;
        String[] nms = tag.split("::");
        for(int i=0,j=nms.length;i<j && sClass != null;i++) {
            sClass = (RubyModule)sClass.getConstant(nms[i]);
        }

        Map props = new HashMap();
        Map val = (Map)(ctor.constructMapping(node));
        for(Iterator iter = val.entrySet().iterator();iter.hasNext();) {
            Map.Entry em = (Map.Entry)iter.next();
            if(em.getKey().toString().startsWith("@")) {
                props.put(em.getKey(),em.getValue());
                iter.remove();
            }
        }

        // If no such struct exists...
        if(sClass == null) {
            IRubyObject[] params = new IRubyObject[val.size()+1];
            params[0] = runtime.newString(tag);
            int i = 1;
            for(Iterator iter = val.entrySet().iterator();iter.hasNext();i++) {
                Map.Entry em = (Map.Entry)iter.next();
                params[i] = ((RubyString)em.getKey()).intern();
            }
            struct_type = RubyStruct.newInstance(runtime.fastGetModule("Struct"),params,Block.NULL_BLOCK);
        } else {
            struct_type = (RubyClass)sClass;
        }
        IRubyObject st = struct_type.callMethod(runtime.getCurrentContext(),"new");
        RubyArray members = RubyStruct.members(struct_type,Block.NULL_BLOCK);
        for(int i=0,j=members.size();i<j;i++) {
            IRubyObject m = members.eltInternal(i);
            st.callMethod(runtime.getCurrentContext(), m.toString() + "=", (IRubyObject)val.get(m));
        }
View Full Code Here

                objClass = (RubyClass)runtime.fastGetModule("YAML").fastGetConstant("Object");
                final RubyHash vars = (RubyHash)(((JRubyConstructor)ctor).constructRubyMapping(node));
                return RuntimeHelpers.invoke(runtime.getCurrentContext(), objClass, "new", runtime.newString(tag), vars);
            }
        }
        final RubyClass theCls = (RubyClass)objClass;
        return constructRuby(ctor,theCls,node);
    }
View Full Code Here

        Ruby runtime = ((JRubyConstructor)ctor).runtime;
        IRubyObject _cl = runtime.fastGetModule("YAML").callMethod(runtime.getCurrentContext(), "tagged_classes").callMethod(runtime.getCurrentContext(),"[]", runtime.newString(tag));
        if(!(_cl instanceof RubyClass)) {
            return null;
        }
        RubyClass clazz = (RubyClass)_cl;
        if(clazz != null && !clazz.isNil()) {
            return constructRuby(ctor, clazz, node);
        }
        return null;
    }
View Full Code Here

            final String[] nms = tag.split("::");
            for(int i=0,j=nms.length;i<j;i++) {
                objClass = (RubyModule)objClass.getConstant(nms[i]);
            }
        }
        final RubyClass theCls = (RubyClass)objClass;
        final RubyObject oo = (RubyObject)theCls.getAllocator().allocate(runtime, theCls);
        final IRubyObject val = (IRubyObject)constructYamlInt(ctor, node);
        oo.callInit(new IRubyObject[]{val},org.jruby.runtime.Block.NULL_BLOCK);
        return oo;
    }
View Full Code Here

TOP

Related Classes of org.jruby.RubyClass$VariableAccessorField

Copyright © 2018 www.massapicom. 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.