org.jruby.RubyClass.isSingleton()方法的使用及代码示例

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

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

RubyClass.isSingleton介绍

暂无

代码示例

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

public Object apply(IRubyObject arg1) {
    if (rubyClass.isInstance(arg1)) {
      if (arg1 instanceof IncludedModuleWrapper ||
          (arg1 instanceof RubyClass && ((RubyClass)arg1).isSingleton())) {
        // do nothing for included wrappers or singleton classes
      } else {
        count[0]++;
        modules.add(arg1); // store the module to avoid concurrent modification exceptions
      }
    }
    return null;
  }
});

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

public Object apply(IRubyObject arg1) {
    if (rubyClass.isInstance(arg1)) {
      if (arg1 instanceof IncludedModuleWrapper ||
          (arg1 instanceof RubyClass && ((RubyClass)arg1).isSingleton())) {
        // do nothing for included wrappers or singleton classes
      } else {
        count[0]++;
        modules.add(arg1); // store the module to avoid concurrent modification exceptions
      }
    }
    return null;
  }
});

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

private static void warnWrite(final Ruby runtime, IRubyObject maybeIO) {
  IRubyObject klass = maybeIO.getMetaClass();
  char sep;
  if (((RubyClass) klass).isSingleton()) {
    klass = maybeIO;
    sep = '.';
  } else {
    sep = '#';
  }
  runtime.getWarnings().warning(klass.toString() + sep + "write is outdated interface which accepts just one argument");
}

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

private static void warnWrite(final Ruby runtime, IRubyObject maybeIO) {
  IRubyObject klass = maybeIO.getMetaClass();
  char sep;
  if (((RubyClass) klass).isSingleton()) {
    klass = maybeIO;
    sep = '.';
  } else {
    sep = '#';
  }
  runtime.getWarnings().warning(klass.toString() + sep + "write is outdated interface which accepts just one argument");
}

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

/** 
 * A variation on newClass that allow passing in an array of supplementary
 * call sites to improve dynamic invocation.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass, CallSite[] extraCallSites) {
  if (superClass == runtime.getClassClass()) throw runtime.newTypeError("can't make subclass of Class");
  if (superClass.isSingleton()) throw runtime.newTypeError("can't make subclass of virtual class");
  return new RubyClass(runtime, superClass, extraCallSites);        
}

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

/**
 * Construct a new class with the given name scoped under Object (global)
 * and with Object as its immediate superclass.
 * Corresponds to rb_class_new in MRI.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass) {
  if (superClass == runtime.getClassClass()) throw runtime.newTypeError("can't make subclass of Class");
  if (superClass.isSingleton()) throw runtime.newTypeError("can't make subclass of virtual class");
  return new RubyClass(runtime, superClass);
}

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

/**
 * A variation on newClass that allow passing in an array of supplementary
 * call sites to improve dynamic invocation.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass, CallSite[] extraCallSites) {
  if (superClass == runtime.getClassClass()) throw runtime.newTypeError("can't make subclass of Class");
  if (superClass.isSingleton()) throw runtime.newTypeError("can't make subclass of virtual class");
  return new RubyClass(runtime, superClass, extraCallSites);
}

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

/** 
 * Construct a new class with the given name scoped under Object (global)
 * and with Object as its immediate superclass.
 * Corresponds to rb_class_new in MRI.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass) {
  if (superClass == runtime.getClassClass()) throw runtime.newTypeError("can't make subclass of Class");
  if (superClass.isSingleton()) throw runtime.newTypeError("can't make subclass of virtual class");
  return new RubyClass(runtime, superClass);        
}

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

/**
 * A variation on newClass that allow passing in an array of supplementary
 * call sites to improve dynamic invocation.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass, CallSite[] extraCallSites) {
  if (superClass == runtime.getClassClass()) throw runtime.newTypeError("can't make subclass of Class");
  if (superClass.isSingleton()) throw runtime.newTypeError("can't make subclass of virtual class");
  return new RubyClass(runtime, superClass, extraCallSites);
}

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

/**
 * Construct a new class with the given name scoped under Object (global)
 * and with Object as its immediate superclass.
 * Corresponds to rb_class_new in MRI.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass) {
  if (superClass == runtime.getClassClass()) throw runtime.newTypeError("can't make subclass of Class");
  if (superClass.isSingleton()) throw runtime.newTypeError("can't make subclass of virtual class");
  return new RubyClass(runtime, superClass);
}

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

/** 
 * Construct a new class with the given name scoped under Object (global)
 * and with Object as its immediate superclass.
 * Corresponds to rb_class_new in MRI.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass) {
  if (superClass == runtime.getClassClass()) throw runtime.newTypeError("can't make subclass of Class");
  if (superClass.isSingleton()) throw runtime.newTypeError("can't make subclass of virtual class");
  return new RubyClass(runtime, superClass);        
}

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

/** 
 * A variation on newClass that allow passing in an array of supplementary
 * call sites to improve dynamic invocation.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass, CallSite[] extraCallSites) {
  if (superClass == runtime.getClassClass()) throw runtime.newTypeError("can't make subclass of Class");
  if (superClass.isSingleton()) throw runtime.newTypeError("can't make subclass of virtual class");
  return new RubyClass(runtime, superClass, extraCallSites);        
}

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

final IRubyObject methodsImpl(ThreadContext context, final boolean all) {
  final RubyArray methods = RubyArray.newArray(context.runtime);
  final Set<String> seen = new HashSet<>();
  RubyClass metaClass = getMetaClass();
  if (metaClass.isSingleton()) {
    metaClass.populateInstanceMethodNames(seen, methods, PRIVATE, false, true, false);
    if (all) {
      metaClass.getSuperClass().populateInstanceMethodNames(seen, methods, PRIVATE, false, true, true);
    }
  } else if (all) {
    metaClass.populateInstanceMethodNames(seen, methods, PRIVATE, false, true, true);
  } // else - do nothing, leave empty
  return methods;
}

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

/** rb_check_inheritable
 * 
 */
public static void checkInheritable(IRubyObject superClass) {
  if (!(superClass instanceof RubyClass)) {
    throw superClass.getRuntime().newTypeError("superclass must be a Class (" + superClass.getMetaClass() + " given)"); 
  }
  if (((RubyClass)superClass).isSingleton()) {
    throw superClass.getRuntime().newTypeError("can't make subclass of virtual class");
  }        
}

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

/** rb_check_inheritable
 * 
 */
public static void checkInheritable(IRubyObject superClass) {
  if (!(superClass instanceof RubyClass)) {
    throw superClass.getRuntime().newTypeError("superclass must be a Class (" + superClass.getMetaClass() + " given)"); 
  }
  if (((RubyClass)superClass).isSingleton()) {
    throw superClass.getRuntime().newTypeError("can't make subclass of virtual class");
  }        
}

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

private void checkSafeTypeToCopy(RubyClass original) {
  Ruby runtime = getRuntime();
  if (original == runtime.getBasicObject()) throw runtime.newTypeError("can't copy the root class");
  if (getSuperClass() == runtime.getBasicObject()) throw runtime.newTypeError("already initialized class");
  if (original.isSingleton()) throw runtime.newTypeError("can't copy singleton class");
}

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

private void checkSafeTypeToCopy(RubyClass original) {
  Ruby runtime = getRuntime();
  if (original == runtime.getBasicObject()) throw runtime.newTypeError("can't copy the root class");
  if (getSuperClass() == runtime.getBasicObject()) throw runtime.newTypeError("already initialized class");
  if (original.isSingleton()) throw runtime.newTypeError("can't copy singleton class");
}

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

/** rb_check_inheritable
 *
 */
public static void checkInheritable(IRubyObject superClass) {
  if (!(superClass instanceof RubyClass)) {
    throw superClass.getRuntime().newTypeError("superclass must be a Class (" + superClass.getMetaClass() + " given)");
  }
  if (((RubyClass) superClass).isSingleton()) {
    throw superClass.getRuntime().newTypeError("can't make subclass of virtual class");
  }
  if (superClass == superClass.getRuntime().getClassClass()) {
    throw superClass.getRuntime().newTypeError("can't make subclass of Class");
  }
}

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

/** rb_check_inheritable
 *
 */
public static void checkInheritable(IRubyObject superClass) {
  if (!(superClass instanceof RubyClass)) {
    throw superClass.getRuntime().newTypeError("superclass must be a Class (" + superClass.getMetaClass() + " given)");
  }
  if (((RubyClass) superClass).isSingleton()) {
    throw superClass.getRuntime().newTypeError("can't make subclass of virtual class");
  }
  if (superClass == superClass.getRuntime().getClassClass()) {
    throw superClass.getRuntime().newTypeError("can't make subclass of Class");
  }
}

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

public IRubyObject singleton_method(IRubyObject name) {
  RubySymbol symbol = TypeConverter.checkID(name);
  final String methodName = symbol.idString();
  final RubyClass klass = metaClass;
  if (klass.isSingleton()) {
    DynamicMethod method = klass.searchMethod(methodName);
    if (klass == method.getDefinedClass()) { // ! method.isUndefined()
      AbstractRubyMethod newMethod = RubyMethod.newMethod(klass, methodName, klass, methodName, method, this);
      newMethod.infectBy(this);
      return newMethod;
    }
  }
  throw getRuntime().newNameError(str(getRuntime(), "undefined method `", symbol,  "' for `", inspect(), "'"), methodName);
}

相关文章

微信公众号

最新文章

更多

RubyClass类方法