I would like to know to how to do in Ruby what I can do with system(\"clear\")
in C.
I wrote a program like
puts \"amit\"
system(\"clear\")
A portable, compromized yet often visually satisfying approach that I use is what I call "crazy putz puts":
counter=0
until counter == 50
puts " "
counter += 1
end
You can use following create a ruby file say check.rb like follwing
puts "amit"
#system "clear"
and run it from console [Salil@localhost Desktop]$ check.rb
o/p
[Salil@localhost Desktop]$ ruby check.rb
amit
[Salil@localhost Desktop]$
now modify check.rb and run it from console
puts "amit"
system "clear"
o/p
[Salil@localhost Desktop]$
For windows users:
Just type this below function in your irb window and you are good to go:
Define this function:
def cls
system('cls')
end
After defining call this function whenever required.
You can use system("clear")
or system("cls")
according to the terminal you are going to print.
system("cls")
.system("clear")
.Or you can use a better way. Check this example.
count = 0
until count == 10
system("cls") || system("clear")
print count
count += 1
sleep 1
end
If you are using MAC OS then use:
system('clear')
Try any of these two in your ruby file:
puts `clear`
or
puts "\e[H\e[2J"