public IRubyObject named_captures(ThreadContext context) {
RubyHash hash = RubyHash.newHash(getRuntime());
if (pattern.numberOfNames() == 0) return hash;
for (Iterator<NameEntry> i = pattern.namedBackrefIterator(); i.hasNext();) {
NameEntry e = i.next();
int[]backrefs = e.getBackRefs();
RubyArray ary = getRuntime().newArray(backrefs.length);
for (int backref : backrefs) ary.append(RubyFixnum.newFixnum(getRuntime(), backref));
hash.fastASet(RubyString.newStringShared(getRuntime(), e.name, e.nameP, e.nameEnd - e.nameP).freeze(context), ary);
}