Our teacher, the Beit Yosef, wrote in section 6: One who had a ruin among the ruins of his fellow, and his fellow stood and fenced the first, second, and third sides, so that this ruin is found to be fenced on three of its sides, we do not obligate him to give anything of the expenditure, for he has not benefited him, and his ruin remains open to the public domain as it was. Therefore, if he fenced the fourth side for him until his ruin is found to be surrounded by a fence, we roll the entire cost upon him, and he gives half of the expenditure that this one spent on the four sides up to four cubits, provided that the place of the wall belongs to both of them. But if the wall belonged to this one who built it, and he built it in his own portion, we only roll upon him a small amount as the judges see fit, for he cannot make use of the walls. And so too, if the surrounded party himself is the one who fenced the fourth side, he has revealed his intent and gives half the expenditure of the three sides if the walls belonged to both of them. Thus far his words. And it is the wording of the Rambam, of blessed memory. And it appears that he did not mean specifically half the expenditure of the three sides, for he must deduct for him half of the fourth wall. And our teacher, the Rema, wrote that all this refers to where he fenced between himself and the surrounded party, but if he fenced from the outside and between him and the surrounded party it is still open, if it is a place where they are accustomed to fence, the surrounded party does not need to pay him anything even when the surrounding party fenced all four sides, for he still needs to fence between himself and the fields around him [Sma]. But if the surrounded party fenced one of the sides, such that he revealed his intent that it is pleasing to him, he is obligated to give according to what the extra surrounding caused him. Thus far his words. And they calculate according to the calculation of the area, how many cubit by cubit there are in the total fields and how many are in this inner one; for example, if in total they are ten by ten, which are one hundred pieces of cubit by cubit, and the inner one is five by five, which is twenty-five cubits in area, it is found that such a surrounding caused him a benefit which is a fourth part of all the fields, and from this he must give half, which is an eighth part, just as if the surrounding were around him, this one would give half and this one half [and this is the intent of the Tur, and in the Sma it should say he shall also give a portion of a third, etc.].
כתב רבינו הב"י בסעי' ו' מי שהיה לו חורבה בין חורבות חבירו ועמד חבירו וגדר רוח ראשונה ושנייה ושלישית שנמצאת חורבה זו מג' רוחותיה גדורה אין מחייבין אותו ליתן מההוצאה כלום שהרי לא הועיל לו והרי חורבתו פתוחה לרה"ר כמו שהיתה לפיכך אם גדר לו רוח רביעית עד שנמצאת חורבתו מוקפת גדר מגלגלים עליו את הכל ונותן חצי ההוצאה שהוציא זה בד' רוחות עד ד' אמות ובלבד שיהיה מקום הכותל של שניהם אבל אם היה הכותל של זה שבנה ובחלקו בנה אין מגלגלין אלא דבר מועט כמו שיראו הדיינים שהרי אינו יכול להשתמש בכתלים וכן אם הניקף עצמו הוא שגדר רוח רביעית הרי גילה דעתו ונותן חצי ההוצאה של ג' רוחות אם היו הכתלים של שניהם עכ"ל והוא לשון הרמב"ם ז"ל ונראה דלאו דווקא קאמר חצי ההוצאה של ג' רוחות דהא צריך לנכות לו חצי כותל רביעית וכתב רבינו הרמ"א דכ"ז מיירי שגדר בינו ובין הניקף אבל גדר מבחוץ ובינו ובין הניקף עדיין פתוח אם הוא מקום שנהגו לגדור אין הניקף צריך לשלם לו כלום אף כשגדר המקיף כל ארבע הרוחות שהרי עדיין צריך לגדור בינו ובין השדות שסביבו [סמ"ע] אבל אם גדר הניקף אחת מן הרוחות דגלי דעתו דניחא ליה חייב ליתן כפי מה שגרם לו היקף יתירה עכ"ל ומחשבין לפי החשבון בתשבורת כמה אמה על אמה יש בכלל השדות וכמה יש בזו הפנימית כגון שבכלל הם עשר על עשר שהם מאה חתיכות של אמה על אמה והפנימית היא ה' על ה' שהיא כ"ה אמה בתשבורת ונמצא שהיקף כזה גרם לו יתרון שהוא חלק רביעי מכל השדות ומזה צריך ליתן מחצה שהוא חלק שמינית כמו אם היה ההיקף סביבו שהיה זה נותן מחצה וזה מחצה [וזה כונת הטור ובסמ"ע צ"ל יתן ג"כ חלק משליש וכו']: