class Nitra::Utils
Public Class Methods
capture_output() { || ... }
click to toggle source
# File lib/nitra/utils.rb, line 22 def self.capture_output old_stdout = $stdout old_stderr = $stderr $stdout = $stderr = io = StringIO.new begin yield ensure $stdout = old_stdout $stderr = old_stderr end io.string end
processor_count()
click to toggle source
The following taken and modified from the ‘parallel’ gem. Licensed under the MIT licence, copyright Michael Grosser.
# File lib/nitra/utils.rb, line 7 def self.processor_count @processor_count ||= case `uname` when /darwin/i (`which hwprefs` != '' ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i when /linux/i `grep -c processor /proc/cpuinfo`.to_i when /freebsd/i `sysctl -n hw.ncpu`.to_i when /solaris2/i `psrinfo -p`.to_i # this is physical cpus afaik else 1 end end