org.jruby.Ruby.defineClass()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中org.jruby.Ruby.defineClass方法的一些代码示例,展示了Ruby.defineClass的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.defineClass方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:defineClass

Ruby.defineClass介绍

[英]Define a new class under the Object namespace. Roughly equivalent to rb_define_class in MRI.
[中]在对象命名空间下定义一个新类。大致相当于MRI中的rb_定义_类。

代码示例

代码示例来源:origin: org.jruby/jruby-complete

public static RubyClass createArrayJavaProxyCreator(ThreadContext context) {
  Ruby runtime = context.runtime;
  RubyClass arrayJavaProxyCreator = runtime.defineClass("ArrayJavaProxyCreator", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
  arrayJavaProxyCreator.defineAnnotatedMethods(ArrayJavaProxyCreator.class);
  return arrayJavaProxyCreator;
}

代码示例来源:origin: org.jruby/jruby-complete

static RubyClass createDateTimeClass(Ruby runtime, RubyClass Date) {
  RubyClass DateTime = runtime.defineClass("DateTime", Date, ALLOCATOR);
  DateTime.setReifiedClass(RubyDateTime.class);
  DateTime.defineAnnotatedMethods(RubyDateTime.class);
  return DateTime;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public static void setup(Ruby runtime) {
  RubyClass cMutex = runtime.defineClass("Mutex", runtime.getObject(), new ObjectAllocator() {
    public IRubyObject allocate(Ruby runtime, RubyClass klass) {
      return new Mutex(runtime, klass);
    }
  });
  cMutex.setReifiedClass(Mutex.class);
  cMutex.defineAnnotatedMethods(Mutex.class);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public static RubyClass createProcClass(Ruby runtime) {
  RubyClass procClass = runtime.defineClass("Proc", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
  runtime.setProc(procClass);
  procClass.index = ClassIndex.PROC;
  procClass.setReifiedClass(RubyProc.class);
  
  procClass.defineAnnotatedMethods(RubyProc.class);
  
  return procClass;
}

代码示例来源:origin: org.jruby/jruby-core

public static RubyClass createArrayJavaProxyCreator(ThreadContext context) {
  Ruby runtime = context.runtime;
  RubyClass arrayJavaProxyCreator = runtime.defineClass("ArrayJavaProxyCreator", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
  arrayJavaProxyCreator.defineAnnotatedMethods(ArrayJavaProxyCreator.class);
  return arrayJavaProxyCreator;
}

代码示例来源:origin: org.jruby/jruby-complete

static RubyClass define(Ruby runtime, RubyClass superClass) {
  RubyClass KeyError = runtime.defineClass("KeyError", superClass, (runtime1, klass) -> new RubyKeyError(runtime1, klass));
  KeyError.defineAnnotatedMethods(RubyKeyError.class);
  KeyError.setReifiedClass(RubyKeyError.class);
  return KeyError;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public static void setup(Ruby runtime) {
  RubyClass cConditionVariable = runtime.defineClass("ConditionVariable", runtime.getObject(), new ObjectAllocator() {
    public IRubyObject allocate(Ruby runtime, RubyClass klass) {
      return new ConditionVariable(runtime, klass);
    }
  });
  cConditionVariable.setReifiedClass(ConditionVariable.class);
  cConditionVariable.defineAnnotatedMethods(ConditionVariable.class);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public void load(final Ruby runtime, boolean wrap) {
    RubyClass cFiber = runtime.defineClass("Fiber", runtime.getObject(), new ObjectAllocator() {
      public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
        return new ThreadFiber(runtime, klazz);
      }
    });

    cFiber.defineAnnotatedMethods(ThreadFiber.class);
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public static RubyClass createBignumClass(Ruby runtime) {
  RubyClass bignum = runtime.defineClass("Bignum", runtime.getInteger(),
      ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
  runtime.setBignum(bignum);
  bignum.index = ClassIndex.BIGNUM;
  bignum.setReifiedClass(RubyBignum.class);
  bignum.defineAnnotatedMethods(RubyBignum.class);
  return bignum;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public static void setup(Ruby runtime) {
  RubyClass cConditionVariable = runtime.defineClass("ConditionVariable", runtime.getObject(), new ObjectAllocator() {
    public IRubyObject allocate(Ruby runtime, RubyClass klass) {
      return new ConditionVariable(runtime, klass);
    }
  });
  cConditionVariable.setReifiedClass(ConditionVariable.class);
  cConditionVariable.defineAnnotatedMethods(ConditionVariable.class);
}

代码示例来源:origin: org.jruby/jruby-complete

public static void createTracePointClass(Ruby runtime) {
  RubyClass tracePoint = runtime.defineClass("TracePoint", runtime.getObject(), new ObjectAllocator() {
    @Override
    public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
      return new TracePoint(runtime, klazz);
    }
  });
  
  tracePoint.defineAnnotatedMethods(TracePoint.class);
}

代码示例来源:origin: org.jruby/jruby-complete

public static RubyClass createRationalClass(Ruby runtime) {
  RubyClass rationalc = runtime.defineClass("Rational", runtime.getNumeric(), RATIONAL_ALLOCATOR);
  runtime.setRational(rationalc);
  rationalc.setClassIndex(ClassIndex.RATIONAL);
  rationalc.setReifiedClass(RubyRational.class);
  
  rationalc.kindOf = new RubyModule.JavaClassKindOf(RubyRational.class);
  rationalc.setMarshal(RATIONAL_MARSHAL);
  rationalc.defineAnnotatedMethods(RubyRational.class);
  rationalc.getSingletonClass().undefineMethod("allocate");
  rationalc.getSingletonClass().undefineMethod("new");
  return rationalc;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public static void setup(Ruby runtime) {
  RubyClass cQueue = runtime.defineClass("Queue", runtime.getObject(), new ObjectAllocator() {
    public IRubyObject allocate(Ruby runtime, RubyClass klass) {
      return new Queue(runtime, klass);
    }
  });
  cQueue.setReifiedClass(Queue.class);
  cQueue.defineAnnotatedMethods(Queue.class);
}

代码示例来源:origin: org.jruby/jruby-complete

public static RubyClass createJRubyObjectInputStream(Ruby runtime) {
  RubyClass result = runtime.defineClass("JRubyObjectInputStream",runtime.getObject(), ALLOCATOR);
  result.defineAnnotatedMethods(JRubyObjectInputStream.class);
  return result;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public static void setup(Ruby runtime) {
  RubyClass cQueue = runtime.defineClass("Queue", runtime.getObject(), new ObjectAllocator() {
    public IRubyObject allocate(Ruby runtime, RubyClass klass) {
      return new Queue(runtime, klass);
    }
  });
  cQueue.setReifiedClass(Queue.class);
  cQueue.defineAnnotatedMethods(Queue.class);
}

代码示例来源:origin: org.jruby/jruby-complete

public static RubyClass createClass(Ruby runtime, RubyClass baseClass) {
  RubyClass exceptionClass = runtime.defineClass(CLASS_NAME, baseClass, NATIVE_EXCEPTION_ALLOCATOR);
  runtime.getObject().deprecateConstant(runtime, CLASS_NAME);
  exceptionClass.defineAnnotatedMethods(NativeException.class);
  return exceptionClass;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/** Create the RubyMethod class and add it to the Ruby runtime.
 * 
 */
public static RubyClass createMethodClass(Ruby runtime) {
  // TODO: NOT_ALLOCATABLE_ALLOCATOR is probably ok here. Confirm. JRUBY-415
  RubyClass methodClass = runtime.defineClass("Method", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
  runtime.setMethod(methodClass);
  methodClass.index = ClassIndex.METHOD;
  methodClass.setReifiedClass(RubyMethod.class);
  
  methodClass.defineAnnotatedMethods(RubyMethod.class);
  
  return methodClass;
}

代码示例来源:origin: org.jruby/jruby-complete

public static RubyClass createInterfaceJavaProxy(ThreadContext context) {
  final Ruby runtime = context.runtime;
  RubyClass InterfaceJavaProxy = runtime.defineClass(
    "InterfaceJavaProxy", runtime.getJavaSupport().getJavaProxyClass(), ALLOCATOR
  );
  RubyClass JavaInterfaceExtended = runtime.defineClass(
    "JavaInterfaceExtender", runtime.getObject(), runtime.getObject().getAllocator()
  );
  JavaInterfaceExtended.defineAnnotatedMethods(JavaInterfaceExtender.class);
  return InterfaceJavaProxy;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/** Create the RubyMethod class and add it to the Ruby runtime.
 * 
 */
public static RubyClass createMethodClass(Ruby runtime) {
  // TODO: NOT_ALLOCATABLE_ALLOCATOR is probably ok here. Confirm. JRUBY-415
  RubyClass methodClass = runtime.defineClass("Method", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
  runtime.setMethod(methodClass);
  methodClass.index = ClassIndex.METHOD;
  methodClass.setReifiedClass(RubyMethod.class);
  
  methodClass.defineAnnotatedMethods(RubyMethod.class);
  
  return methodClass;
}

代码示例来源:origin: org.jruby/jruby-core

static void createTCPSocket(Ruby runtime) {
  RubyClass rb_cTCPSocket = runtime.defineClass("TCPSocket", runtime.getClass("IPSocket"), TCPSOCKET_ALLOCATOR);
  rb_cTCPSocket.defineAnnotatedMethods(RubyTCPSocket.class);
  runtime.getObject().setConstant("TCPsocket",rb_cTCPSocket);
}

相关文章

Ruby类方法