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

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

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

Ruby.getArray介绍

暂无

代码示例

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

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

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

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

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

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

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

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

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

  1. @Override
  2. public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg) {
  3. if (self.getMetaClass() == context.runtime.getArray()) {
  4. return ((RubyArray) self).aref(arg);
  5. }
  6. return super.call(context, caller, self, arg);
  7. }
  8. }

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

  1. @Override
  2. public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg0, IRubyObject arg1) {
  3. Ruby runtime = context.runtime;
  4. if (self.getMetaClass() == runtime.getArray()) {
  5. RubyArray array = (RubyArray)self;
  6. return array.aset(arg0, arg1);
  7. }
  8. return super.call(context, caller, self, arg0, arg1);
  9. }
  10. }

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

  1. @Override
  2. public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, long fixnum) {
  3. if (self.getMetaClass() == context.runtime.getArray()) {
  4. return ((RubyArray) self).entry(fixnum);
  5. }
  6. return super.call(context, caller, self, fixnum);
  7. }

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

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

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

  1. public static IRubyObject aryToAry(ThreadContext context, IRubyObject value) {
  2. if (value instanceof RubyArray) return value;
  3. if (value.respondsTo("to_ary")) {
  4. return TypeConverter.convertToType(context, value, context.runtime.getArray(), "to_ary", false);
  5. }
  6. return context.runtime.newArray(value);
  7. }

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

  1. @Override
  2. public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg) {
  3. if (self.getMetaClass() == context.runtime.getArray()) {
  4. return ((RubyArray) self).aref(arg);
  5. }
  6. return super.call(context, caller, self, arg);
  7. }
  8. }

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

  1. /** rb_ary_to_a
  2. *
  3. */
  4. @JRubyMethod(name = "to_a")
  5. @Override
  6. public RubyArray to_a() {
  7. if(getMetaClass() != getRuntime().getArray()) {
  8. return aryDup();
  9. }
  10. return this;
  11. }

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

  1. /**
  2. * Tries to convert this object to a Ruby Array using the "to_ary" method.
  3. * @return array representation of this
  4. */
  5. @Override
  6. public RubyArray convertToArray() {
  7. Ruby runtime = getRuntime();
  8. ThreadContext context = runtime.getCurrentContext();
  9. BasicObjectSites sites = sites(context);
  10. return (RubyArray) TypeConverter.convertToType(context, this, runtime.getArray(), sites.to_ary_checked);
  11. }

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

  1. @JRubyMethod
  2. public IRubyObject pop(ThreadContext context, IRubyObject num) {
  3. unpack();
  4. modifyCheck();
  5. RubyArray result = makeSharedFirst(context, num, true, context.runtime.getArray());
  6. realLength -= result.realLength;
  7. return result;
  8. }

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

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

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

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

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

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

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

  1. public static RubyArray convertToRubyArrayWithCoerce(Ruby runtime, IRubyObject value) {
  2. if (value instanceof RubyArray) return ((RubyArray)value);
  3. IRubyObject newValue = TypeConverter.convertToType(value, runtime.getArray(), "to_ary", false);
  4. if (newValue.isNil()) {
  5. return RubyArray.newArrayLight(runtime, value);
  6. }
  7. // must be array by now, or error
  8. if (!(newValue instanceof RubyArray)) {
  9. throw runtime.newTypeError(newValue.getMetaClass() + "#" + "to_ary" + " should return Array");
  10. }
  11. return (RubyArray)newValue;
  12. }

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

  1. public static RubyArray convertToRubyArrayWithCoerce(Ruby runtime, IRubyObject value) {
  2. if (value instanceof RubyArray) return ((RubyArray)value);
  3. IRubyObject newValue = TypeConverter.convertToType(value, runtime.getArray(), "to_ary", false);
  4. if (newValue.isNil()) {
  5. return RubyArray.newArrayLight(runtime, value);
  6. }
  7. // must be array by now, or error
  8. if (!(newValue instanceof RubyArray)) {
  9. throw runtime.newTypeError(newValue.getMetaClass() + "#" + "to_ary" + " should return Array");
  10. }
  11. return (RubyArray)newValue;
  12. }

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

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

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

  1. @Override
  2. public boolean isInstance(IRubyObject object) {
  3. if (!super.isInstance(object)) {
  4. return false;
  5. }
  6. RubyArray array = (RubyArray) object;
  7. boolean ret = array.size() == 2
  8. && object.getRuntime().getArray().isInstance((IRubyObject) array.get(0))
  9. && (null == array.get(1) || LIST_ITEM_CLASS.isInstance((IRubyObject) array.get(1)));
  10. return ret;
  11. }

相关文章

Ruby类方法