示例#1
0
 @Specialization
 public RubyArray unpack(RubyString string, RubyString format) {
   final org.jruby.RubyArray jrubyArray =
       Pack.unpack(getContext().getRuntime(), string.getBytes(), format.getBytes());
   return RubyArray.specializedFromObjects(
       getContext().getCoreLibrary().getArrayClass(), jrubyArray.toArray());
 }
示例#2
0
    @Specialization
    public RubyArray split(RubyString string, RubyString sep) {
      final String[] components = string.toString().split(Pattern.quote(sep.toString()));

      final Object[] objects = new Object[components.length];

      for (int n = 0; n < objects.length; n++) {
        objects[n] = getContext().makeString(components[n]);
      }

      return RubyArray.specializedFromObjects(
          getContext().getCoreLibrary().getArrayClass(), objects);
    }
示例#3
0
 @Specialization
 public RubyArray split(RubyString string, RubyRegexp sep) {
   return RubyArray.specializedFromObjects(
       getContext().getCoreLibrary().getArrayClass(), sep.split(string.toString()));
 }
示例#4
0
 @Specialization
 public RubyArray scan(RubyString string, RubyRegexp regexp) {
   return RubyArray.specializedFromObjects(
       getContext().getCoreLibrary().getArrayClass(), regexp.scan(string));
 }