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

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

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

RubyModule.isSingleton介绍

暂无

代码示例

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

public List<IRubyObject> getAncestorList() {
  ArrayList<IRubyObject> list = new ArrayList<IRubyObject>();
  for (RubyModule module = this; module != null; module = module.getSuperClass()) {
    if(!module.isSingleton()) list.add(module.getNonIncludedClass());
  }
  return list;
}

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

public List<IRubyObject> getAncestorList() {
  ArrayList<IRubyObject> list = new ArrayList<IRubyObject>();
  for (RubyModule module = this; module != null; module = module.getSuperClass()) {
    if(!module.isSingleton()) list.add(module.getNonIncludedClass());
  }
  return list;
}

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

@JRubyMethod(name = "singleton_class?")
public IRubyObject singleton_class_p(ThreadContext context) {
  return context.runtime.newBoolean(isSingleton());
}

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

@JRubyMethod(name = "singleton_class?")
public IRubyObject singleton_class_p(ThreadContext context) {
  return context.runtime.newBoolean(isSingleton());
}

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

private static void callNormalMethodHook(RubyModule containingClass, ThreadContext context, RubySymbol name) {
  // 'class << state.self' and 'class << obj' uses defn as opposed to defs
  if (containingClass.isSingleton()) {
    callSingletonMethodHook(((MetaClass) containingClass).getAttached(), context, name);
  } else {
    containingClass.callMethod(context, "method_added", name);
  }
}

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

private static void callNormalMethodHook(RubyModule containingClass, ThreadContext context, RubySymbol name) {
  // 'class << state.self' and 'class << obj' uses defn as opposed to defs
  if (containingClass.isSingleton()) {
    callSingletonMethodHook(((MetaClass) containingClass).getAttached(), context, name);
  } else {
    containingClass.callMethod(context, "method_added", name);
  }
}

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

private static void callNormalMethodHook(RubyModule containingClass, ThreadContext context, RubySymbol name) {
  // 'class << state.self' and 'class << obj' uses defn as opposed to defs
  if (containingClass.isSingleton()) {
    callSingletonMethodHook(((MetaClass) containingClass).getAttached(), context, name);
  } else {
    containingClass.callMethod(context, "method_added", name);
  }
}

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

private static void callNormalMethodHook(RubyModule containingClass, ThreadContext context, RubySymbol name) {
  // 'class << state.self' and 'class << obj' uses defn as opposed to defs
  if (containingClass.isSingleton()) {
    callSingletonMethodHook(((MetaClass) containingClass).getAttached(), context, name);
  } else {
    containingClass.callMethod(context, "method_added", name);
  }
}

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

@JIT @Interp
public static IRubyObject isDefinedClassVar(ThreadContext context, RubyModule receiver, String name, IRubyObject definedMessage) {
  boolean defined = receiver.isClassVarDefined(name);
  if (!defined && receiver.isSingleton()) { // Look for class var in singleton if it is one.
    IRubyObject attached = ((MetaClass) receiver).getAttached();
    if (attached instanceof RubyModule) defined = ((RubyModule) attached).isClassVarDefined(name);
  }
  return defined ? definedMessage : context.nil;
}

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

@JIT @Interp
public static IRubyObject isDefinedClassVar(ThreadContext context, RubyModule receiver, String name, IRubyObject definedMessage) {
  boolean defined = receiver.isClassVarDefined(name);
  if (!defined && receiver.isSingleton()) { // Look for class var in singleton if it is one.
    IRubyObject attached = ((MetaClass) receiver).getAttached();
    if (attached instanceof RubyModule) defined = ((RubyModule) attached).isClassVarDefined(name);
  }
  return defined ? definedMessage : context.nil;
}

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

@Override
public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) {
  Ruby runtime = context.runtime;
  RubyModule cm = (RubyModule) getObject().retrieve(context, self, currDynScope, temp);
  String name = getName().string;
  boolean defined = cm.isClassVarDefined(name);
  if (!defined && cm.isSingleton()) { // Not found look for cvar on singleton
    IRubyObject attached = ((MetaClass)cm).getAttached();
    if (attached instanceof RubyModule) defined = ((RubyModule)attached).isClassVarDefined(name);
  }
  return runtime.newBoolean(defined);
}

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

@Override
public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) {
  Ruby runtime = context.runtime;
  RubyModule cm = (RubyModule) getObject().retrieve(context, self, currDynScope, temp);
  String name = getName().string;
  boolean defined = cm.isClassVarDefined(name);
  if (!defined && cm.isSingleton()) { // Not found look for cvar on singleton
    IRubyObject attached = ((MetaClass)cm).getAttached();
    if (attached instanceof RubyModule) defined = ((RubyModule)attached).isClassVarDefined(name);
  }
  return runtime.newBoolean(defined);
}

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

public static RubyModule getClassVariableBase(Ruby runtime, StaticScope scope) {
  RubyModule rubyClass = scope.getModule();
  while (rubyClass.isSingleton() || rubyClass == runtime.getDummy()) {
    // We ran out of scopes to check
    if (scope == null) return null;
    scope = scope.getPreviousCRefScope();
    rubyClass = scope.getModule();
    if (scope.getPreviousCRefScope() == null) {
      runtime.getWarnings().warn(ID.CVAR_FROM_TOPLEVEL_SINGLETON_METHOD, "class variable access from toplevel singleton method");
    }
  }
  return rubyClass;
}

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

public static RubyModule getClassVariableBase(Ruby runtime, StaticScope scope) {
  RubyModule rubyClass = scope.getModule();
  while (rubyClass.isSingleton() || rubyClass == runtime.getDummy()) {
    // We ran out of scopes to check
    if (scope == null) return null;
    scope = scope.getPreviousCRefScope();
    rubyClass = scope.getModule();
    if (scope.getPreviousCRefScope() == null) {
      runtime.getWarnings().warn(ID.CVAR_FROM_TOPLEVEL_SINGLETON_METHOD, "class variable access from toplevel singleton method");
    }
  }
  return rubyClass;
}

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

@Override
  public IRubyObject assign(Ruby runtime, ThreadContext context, IRubyObject self, IRubyObject value, Block block, boolean checkArity) {        
    if (runtime.isVerbose() && context.getRubyClass().isSingleton()) {
      runtime.getWarnings().warn(ID.DECLARING_SCLASS_VARIABLE, getPosition(), "Declaring singleton class variable.");
    }
    
    ASTInterpreter.getClassVariableBase(context, runtime).setClassVar(name, value);
    
    return runtime.getNil();
  }
}

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

@Override
  public IRubyObject assign(Ruby runtime, ThreadContext context, IRubyObject self, IRubyObject value, Block block, boolean checkArity) {        
    if (runtime.isVerbose() && context.getRubyClass().isSingleton()) {
      runtime.getWarnings().warn(ID.DECLARING_SCLASS_VARIABLE, getPosition(), "Declaring singleton class variable.");
    }
    
    ASTInterpreter.getClassVariableBase(context, runtime).setClassVar(name, value);
    
    return runtime.getNil();
  }
}

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

@JRubyMethod(name = "alias_method", required = 2, visibility = PRIVATE)
public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) {
  String newName = newId.asJavaString();
  defineAlias(newName, oldId.asJavaString());
  RubySymbol newSym = newId instanceof RubySymbol ? (RubySymbol)newId :
    context.runtime.newSymbol(newName);
  if (isSingleton()) {
    ((MetaClass)this).getAttached().callMethod(context, "singleton_method_added", newSym);
  } else {
    callMethod(context, "method_added", newSym);
  }
  return this;
}

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

@JRubyMethod(name = "alias_method", required = 2, visibility = PRIVATE)
public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) {
  String newName = newId.asJavaString();
  defineAlias(newName, oldId.asJavaString());
  RubySymbol newSym = newId instanceof RubySymbol ? (RubySymbol)newId :
    context.runtime.newSymbol(newName);
  if (isSingleton()) {
    ((MetaClass)this).getAttached().callMethod(context, "singleton_method_added", newSym);
  } else {
    callMethod(context, "method_added", newSym);
  }
  return this;
}

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

@JRubyMethod(name = "alias_method", required = 2)
public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) {
  RubySymbol newSym = TypeConverter.checkID(newId);
  RubySymbol oldSym = TypeConverter.checkID(oldId); //  MRI uses rb_to_id but we return existing symbol
  defineAlias(newSym.idString(), oldSym.idString());
  if (isSingleton()) {
    ((MetaClass) this).getAttached().callMethod(context, "singleton_method_added", newSym);
  } else {
    callMethod(context, "method_added", newSym);
  }
  return this;
}

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

@JRubyMethod(name = "alias_method", required = 2)
public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) {
  RubySymbol newSym = TypeConverter.checkID(newId);
  RubySymbol oldSym = TypeConverter.checkID(oldId); //  MRI uses rb_to_id but we return existing symbol
  defineAlias(newSym.idString(), oldSym.idString());
  if (isSingleton()) {
    ((MetaClass) this).getAttached().callMethod(context, "singleton_method_added", newSym);
  } else {
    callMethod(context, "method_added", newSym);
  }
  return this;
}

相关文章

微信公众号

最新文章

更多

RubyModule类方法