On ruby I can do
require "stringio"
def with_captured_stdout
begin
old_stdout = $stdout
$stdout = StringIO.new('','w')
yield
$stdout.string
ensure
$stdout = old_stdout
end
end
and later call it like
str = with_captured_stdout { Solution.main("Greetings from Javatlacati") }
but on crystal-lang I can refer to global variable $stdout
without getting the corresponding error
$global_variables are not supported, use @@class_variables instead
is there any workaround? Thank you in advance.