Size effect of Ruderman―Kittel―Kasuya―Yosida interaction mediated by electrons in nanoribbons