From e93f819cbd1201179a4e27e5e8dfec50c37c6280 Mon Sep 17 00:00:00 2001 From: Rob Dupuis Date: Tue, 5 May 2015 11:30:42 +0100 Subject: [PATCH] Do not mutate @stdout or @stderr strings Calling @stdout.clear broke airbrussh, and was hard to debug. This commit restores the previous (better) behaviour of simply assigning a new blank string when clearing. --- lib/sshkit/command.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/sshkit/command.rb b/lib/sshkit/command.rb index f37bcdbc..9ae4c755 100644 --- a/lib/sshkit/command.rb +++ b/lib/sshkit/command.rb @@ -63,7 +63,7 @@ def on_stdout(channel, data) end def clear_stdout_lines - split_and_clear_stream(@stdout) + split_and_clear_stream(:@stdout) end def on_stderr(channel, data) @@ -73,7 +73,7 @@ def on_stderr(channel, data) end def clear_stderr_lines - split_and_clear_stream(@stderr) + split_and_clear_stream(:@stderr) end def exit_status=(new_exit_status) @@ -220,8 +220,9 @@ def sanitize_command! end end - def split_and_clear_stream(stream) - stream.lines.to_a.tap { stream.clear } # Convert lines enumerable to an array for ruby 1.9 + def split_and_clear_stream(stream_name) + # Convert lines enumerable to an array for ruby 1.9 + instance_variable_get(stream_name).lines.to_a.tap { instance_variable_set(stream_name, '') } end def call_interaction_handler(channel, data, callback_name)