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

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

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

Ruby.getArray介绍

暂无

代码示例

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

private RubyArray(Ruby runtime, IRubyObject[] vals) {
  super(runtime, runtime.getArray());
  this.values = vals;
  this.realLength = vals.length;
}

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

private RubyArray(Ruby runtime, IRubyObject[] vals, boolean objectSpace) {
  super(runtime, runtime.getArray(), objectSpace);
  this.values = vals;
  this.realLength = vals.length;
}

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

private RubyArray(Ruby runtime, IRubyObject[] vals, int begin, int length, boolean objectSpace) {
  super(runtime, runtime.getArray(), objectSpace);
  this.values = vals;
  this.begin = begin;
  this.realLength = length;
}

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

@Deprecated // no-longer-used
public IRubyObject javaArrayFromRubyArray(ThreadContext context, IRubyObject fromArray) {
  if ( ! ( fromArray instanceof RubyArray ) ) {
    final Ruby runtime = context.runtime;
    throw runtime.newTypeError(fromArray, runtime.getArray());
  }
  return javaArrayFromRubyArray(context, (RubyArray) fromArray);
}

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

@Override
  public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg) {
    if (self.getMetaClass() == context.runtime.getArray()) {
      return ((RubyArray) self).aref(arg);
    }
    return super.call(context, caller, self, arg);
  }
}

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

@Override
  public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg0, IRubyObject arg1) {
    Ruby runtime = context.runtime;
    if (self.getMetaClass() == runtime.getArray()) {
      RubyArray array = (RubyArray)self;
      return array.aset(arg0, arg1);
    }
    return super.call(context, caller, self, arg0, arg1);
  }
}

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

@Override
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, long fixnum) {
  if (self.getMetaClass() == context.runtime.getArray()) {
    return ((RubyArray) self).entry(fixnum);
  }
  return super.call(context, caller, self, fixnum);
}

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

public static RubyArray viewArgsArray(ThreadContext context, RubyArray rubyArray, int preArgsCount, int postArgsCount) {
  int n = rubyArray.getLength();
  if (preArgsCount + postArgsCount >= n) {
    return RubyArray.newEmptyArray(context.runtime);
  }
  return (RubyArray)rubyArray.subseq(context.runtime.getArray(), preArgsCount, n - preArgsCount - postArgsCount, true);
}

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

public static IRubyObject aryToAry(ThreadContext context, IRubyObject value) {
  if (value instanceof RubyArray) return value;
  if (value.respondsTo("to_ary")) {
    return TypeConverter.convertToType(context, value, context.runtime.getArray(), "to_ary", false);
  }
  return context.runtime.newArray(value);
}

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

@Override
  public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg) {
    if (self.getMetaClass() == context.runtime.getArray()) {
      return ((RubyArray) self).aref(arg);
    }
    return super.call(context, caller, self, arg);
  }
}

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

/** rb_ary_to_a
 *
 */
@JRubyMethod(name = "to_a")
@Override
public RubyArray to_a() {
  if(getMetaClass() != getRuntime().getArray()) {
    return aryDup();
  }
  return this;
}

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

/**
 * Tries to convert this object to a Ruby Array using the "to_ary" method.
 * @return array representation of this
 */
@Override
public RubyArray convertToArray() {
  Ruby runtime = getRuntime();
  ThreadContext context = runtime.getCurrentContext();
  BasicObjectSites sites = sites(context);
  return (RubyArray) TypeConverter.convertToType(context, this, runtime.getArray(), sites.to_ary_checked);
}

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

@JRubyMethod
public IRubyObject pop(ThreadContext context, IRubyObject num) {
  unpack();
  modifyCheck();
  RubyArray result = makeSharedFirst(context, num, true, context.runtime.getArray());
  realLength -= result.realLength;
  return result;
}

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

@Override
public RubyArray aryDup() {
  if (!packed()) return super.aryDup();
  return new RubyArrayTwoObject(getRuntime().getArray(), this);
}

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

@Override
public RubyArray aryDup() {
  if (!packed()) return super.aryDup();
  return new RubyArrayOneObject(getRuntime().getArray(), this);
}

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

@JRubyMethod(name = "new", meta = true, required = 3, optional = 1)
public static final IRubyObject newStructLayout(ThreadContext context, IRubyObject klass, 
    IRubyObject[] args) {
  IRubyObject rbFields = args[0], size = args[1], alignment = args[2];
  if (!(rbFields instanceof RubyArray)) {
    throw context.runtime.newTypeError(rbFields, context.runtime.getArray());
  }
  List<IRubyObject> fields = Arrays.asList(((RubyArray) rbFields).toJavaArrayMaybeUnsafe());
  return new StructLayout(context.runtime, (RubyClass) klass, fields,
      RubyNumeric.num2int(size), RubyNumeric.num2int(alignment));
}

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

public static RubyArray convertToRubyArrayWithCoerce(Ruby runtime, IRubyObject value) {
  if (value instanceof RubyArray) return ((RubyArray)value);
  
  IRubyObject newValue = TypeConverter.convertToType(value, runtime.getArray(), "to_ary", false);
  if (newValue.isNil()) {
    return RubyArray.newArrayLight(runtime, value);
  }
  
  // must be array by now, or error
  if (!(newValue instanceof RubyArray)) {
    throw runtime.newTypeError(newValue.getMetaClass() + "#" + "to_ary" + " should return Array");
  }
  
  return (RubyArray)newValue;
}

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

public static RubyArray convertToRubyArrayWithCoerce(Ruby runtime, IRubyObject value) {
  if (value instanceof RubyArray) return ((RubyArray)value);
  
  IRubyObject newValue = TypeConverter.convertToType(value, runtime.getArray(), "to_ary", false);
  if (newValue.isNil()) {
    return RubyArray.newArrayLight(runtime, value);
  }
  
  // must be array by now, or error
  if (!(newValue instanceof RubyArray)) {
    throw runtime.newTypeError(newValue.getMetaClass() + "#" + "to_ary" + " should return Array");
  }
  
  return (RubyArray)newValue;
}

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

@JIT
public static RubyArray irSplat(ThreadContext context, IRubyObject ary) {
  Ruby runtime = context.runtime;
  IRubyObject tmp = TypeConverter.convertToTypeWithCheck(context, ary, runtime.getArray(), sites(context).to_a_checked);
  if (tmp.isNil()) {
    tmp = runtime.newArray(ary);
  }
  else if (true /**RTEST(flag)**/) { // this logic is only used for bare splat, and MRI dups
    tmp = ((RubyArray)tmp).aryDup();
  }
  return (RubyArray)tmp;
}

代码示例来源:origin: asciidoctor/asciidoctorj

@Override
public boolean isInstance(IRubyObject object) {
  if (!super.isInstance(object)) {
    return false;
  }
  RubyArray array = (RubyArray) object;
  boolean ret = array.size() == 2
      && object.getRuntime().getArray().isInstance((IRubyObject) array.get(0))
      && (null == array.get(1) || LIST_ITEM_CLASS.isInstance((IRubyObject) array.get(1)));
  return ret;
}

相关文章

微信公众号

最新文章

更多

Ruby类方法