Module: Kernel

Defined in:
lib/kcd/core_ext/kernel.rb

Instance Method Summary collapse

Instance Method Details

#quietlyObject

Silences both STDOUT and STDERR, even for subprocesses.

quietly { system 'bundle install' }


26
27
28
29
30
31
32
# File 'lib/kcd/core_ext/kernel.rb', line 26

def quietly
  silence_stream(STDOUT) do
    silence_stream(STDERR) do
      yield
    end
  end
end

#silence_stream(stream) ⇒ Object

Silences any stream for the duration of the block.

silence_stream(STDOUT) do
  puts 'This will never be seen'
end

puts 'But this will'


13
14
15
16
17
18
19
20
# File 'lib/kcd/core_ext/kernel.rb', line 13

def silence_stream(stream)
  old_stream = stream.dup
  stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
  stream.sync = true
  yield
ensure
  stream.reopen(old_stream)
end