Esempio n. 1
0
 // @RubyLevelMethod(name="nitems")
 public RubyValue nitems() {
   int n = 0;
   for (int i = 0; i < size(); i++) {
     if (get(i) != RubyConstant.QNIL) n++;
   }
   return ObjectFactory.createFixnum(n);
 }
Esempio n. 2
0
 // @RubyLevelMethod(name="new", singleton=true)
 public static RubyValue newArray(RubyValue receiver, RubyArray args, RubyBlock block) {
   RubyArray a;
   if (null == args) {
     a = new RubyArray();
   } else if (null == block) {
     if (args.get(0) instanceof RubyArray) {
       a = (RubyArray) args.get(0).clone();
     } else {
       RubyFixnum size = (RubyFixnum) args.get(0);
       RubyValue default_value = args.get(1);
       a = ObjectFactory.createArray(size.toInt(), default_value);
     }
   } else {
     RubyFixnum size = (RubyFixnum) args.get(0);
     a = new RubyArray();
     for (int i = 0; i < size.toFloat(); i++) {
       RubyValue return_value = block.invoke(receiver, ObjectFactory.createFixnum(i));
       a.add(return_value);
     }
   }
   a.setRubyClass((RubyClass) receiver);
   return a;
 }
Esempio n. 3
0
 // @RubyLevelMethod(name="rindex")
 public RubyValue rindex(RubyValue arg) {
   for (int i = size() - 1; i >= 0; i--) {
     if (get(i).equals(arg)) return ObjectFactory.createFixnum(i);
   }
   return RubyConstant.QNIL;
 }
Esempio n. 4
0
 // @RubyLevelMethod(name="hash")
 public RubyFixnum hash() {
   return ObjectFactory.createFixnum(hashCode());
 }
Esempio n. 5
0
 // @RubyLevelMethod(name="eql?")
 public RubyValue opEql(RubyValue v) {
   return ObjectFactory.createBoolean(equals(v, false));
 }
Esempio n. 6
0
 // @RubyLevelMethod(name="length")
 public RubyFixnum length() {
   return ObjectFactory.createFixnum(this.array_.size());
 }
Esempio n. 7
0
 // @RubyLevelMethod(name="empty?")
 public RubyValue empty_p() {
   return ObjectFactory.createBoolean(this.array_.isEmpty());
 }
Esempio n. 8
0
 // @RubyLevelMethod(name="pack")
 public RubyValue pack(RubyValue arg) {
   String format = ((RubyString) arg).toString();
   return ObjectFactory.createString(ArrayPacker.pack(this, format));
 }