Question

Is it possible to change all newline printed on $stderr.puts or $stderr.print into some other characters?

for example, changing into :.:

$stderr.print "123.45\n\n"
=> 123.45 :. :.
$stderr.puts 'yay'
=> yay :.

If it's possible, how?

Was it helpful?

Solution

As @Stefan wrote in the comment, probably you should use an HTML <pre> tag instead, or CSS white-space: pre directive on a non-pre element. Anyway:

$stderr.print:

def $stderr.print(*args)
  super *args.map { |v| v.to_s.gsub("\n", "<br>") }
end
$stderr.print "ciao\n" #=> nil
ciao<br>

$stderr.puts:

def $stderr.puts(*args)
  print *args.map { |v| v.to_s + "\n" }
end
$stderr.puts "ciao" #=> nil
ciao<br>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top