0

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 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.

Ruslan López
  • 4,433
  • 2
  • 26
  • 37

1 Answers1

2

Currently there's no easy way to capture stdout or stderr in the crystal standard library, however here's a shard which looks to do that: https://github.com/mosop/stdio.

Stephie
  • 3,135
  • 17
  • 22