Esempio n. 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());
 }
Esempio n. 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);
    }
Esempio n. 3
0
 @Specialization
 public RubyArray split(RubyString string, RubyRegexp sep) {
   return RubyArray.specializedFromObjects(
       getContext().getCoreLibrary().getArrayClass(), sep.split(string.toString()));
 }
Esempio n. 4
0
 @Specialization
 public RubyArray scan(RubyString string, RubyRegexp regexp) {
   return RubyArray.specializedFromObjects(
       getContext().getCoreLibrary().getArrayClass(), regexp.scan(string));
 }