Example #1
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;
 }
Example #2
0
 // @RubyLevelMethod(name="[]")
 public static RubyValue create(RubyValue receiver) {
   RubyArray a = new RubyArray();
   a.setRubyClass((RubyClass) receiver);
   return a;
 }
Example #3
0
 // @RubyLevelMethod(name="new", singleton=true)
 public static RubyValue newArray(RubyValue receiver, RubyBlock block) {
   RubyArray a = new RubyArray();
   a.setRubyClass((RubyClass) receiver);
   return a;
 }
Example #4
0
 // @RubyLevelMethod(name="[]")
 public static RubyValue create(RubyValue receiver, RubyArray args) {
   RubyArray a = args.copy();
   a.setRubyClass((RubyClass) receiver);
   return a;
 }