Michael Michael - 4 months ago 32
Ruby Question

Clear screen before any output to console

I use HighLine gem for UI. I want to clear the screen before output any data. Which method should I use? Patch some Ruby methods like

? Patch HighLine? Change my app in some way? At the moment it has
class with various methods which call HighLine functions for interacting with user. Or maybe HighLine has a built-in method to do that?


Well, the requirements are not clear and I won’t recommend this way, but the stated problem might be solved with:

$stdout.singleton_class.prepend(Module.new do
  def write(string)
    super("\e[2J" << string)

I think, this answer is not suitable for the OP, but it perfectly answers the exact question asked.