Skip to content

Instantly share code, notes, and snippets.

@misku
Created July 18, 2014 10:30
Show Gist options
  • Save misku/ef2ae4a10eb338ebd93b to your computer and use it in GitHub Desktop.
Save misku/ef2ae4a10eb338ebd93b to your computer and use it in GitHub Desktop.
Prevent output of command triggered
def self.preventOutput(msg)
exeption = false
# Prevent block from outputting anything
original_stdout = $stdout
$stdout = fake = StringIO.new
begin
# Peform the action
yield if block_given?
rescue Exception => e
exeption = true
ensure
$stdout = original_stdout
if exeption
puts msg unless msg.empty?
else
puts fake.string
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment