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