If you understand correctly that you want to show some kind of HTML preview of the text that the user enters into the text field, for example, a preview that appears below the text field here in stackoverflow.
Probably the easiest way is CSS.
#preview {
height: 4em;
overflow: hidden;
}
This should work if the line height is normal. This, of course, just hides the extra text. If hiding is unacceptable and you only need to generate 4 lines from Ruby to display, then this is harder. I do not know Ruby, so I can not give code examples. First, I would divide the text anywhere, where would be forced to a new line, such as <br>, <p>,<li> .. , , . , Ruby, , X, X - , . , , . , - , 4 .
, .