@@ -828,35 +828,37 @@ private IRubyObject aset(int idx, IRubyObject value) {
828828 return values [newIdx ] = value ;
829829 }
830830
831- // NOTE: copied from RubyArray, both RE, Struct, and Array should share one impl
832831 @ JRubyMethod (rest = true )
833832 public IRubyObject values_at (IRubyObject [] args ) {
833+ final Ruby runtime = metaClass .runtime ;
834834 final int olen = values .length ;
835835 RubyArray result = getRuntime ().newArray (args .length );
836836
837837 for (int i = 0 ; i < args .length ; i ++) {
838838 final IRubyObject arg = args [i ];
839- if ( arg instanceof RubyFixnum ) {
839+ if (arg instanceof RubyFixnum ) {
840840 result .append ( aref (arg ) );
841841 continue ;
842842 }
843843
844- final int [] begLen ;
845- if ( ! ( arg instanceof RubyRange ) ) {
846- // do result.append
847- }
848- else if ( ( begLen = ((RubyRange ) args [i ]).begLenInt (olen , 0 ) ) == null ) {
849- continue ;
850- }
851- else {
844+ final int [] begLen = new int [2 ];
845+ if (arg instanceof RubyRange &&
846+ RubyRange .rangeBeginLength (runtime .getCurrentContext (),(RubyRange ) args [i ], olen , begLen , 1 ).isTrue ()) {
852847 final int beg = begLen [0 ];
853848 final int len = begLen [1 ];
854- for (int j = 0 ; j < len ; j ++) {
855- result .append ( aref (j + beg ) );
849+ int end = olen < beg + len ? olen : beg + len ;
850+ int j ;
851+ for (j = beg ; j < end ; j ++) {
852+ result .push (aref (j ));
853+ }
854+ if ( beg + len > j ) {
855+ IRubyObject [] tmp = new IRubyObject [beg + len - j ];
856+ Helpers .fillNil (tmp , getRuntime ());
857+ result .push (tmp );
856858 }
857859 continue ;
858860 }
859- result .append ( aref (RubyNumeric .num2int (arg )) );
861+ result .push ( aref (RubyNumeric .num2int (arg )));
860862 }
861863
862864 return result ;
0 commit comments