Specifically http://www.scintilla.org/ScintillaDoc.html#SCI_GETFOLDLEVEL
Something like (pseudo code):
``` curLine = GetCurrentLine(); curFoldLevel = GetFoldLevel(curLine++); while (!endOfFile) { thisFoldLevel = GetFoldLevel(curLine++); if (thisFoldLevel == curFoldLevel) { // this is the matching closing line } } ```
It wouldn't work if ruby allows the block ending on the same line as the block start though (I don't know ruby).