Class: Bmrace::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/bmrace/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commands) ⇒ Command

Returns a new instance of Command.



9
10
11
# File 'lib/bmrace/command.rb', line 9

def initialize(commands)
  @commands = commands
end

Class Method Details

.ready(*arguments) ⇒ Object



4
5
6
# File 'lib/bmrace/command.rb', line 4

def ready(*arguments)
  new(arguments)
end

Instance Method Details

#go!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bmrace/command.rb', line 13

def go!
  threads = {}
  results = {}

  @commands.each do |cmd|
    threads[cmd] = Thread.new do
      start_time = Time.now
      `#{cmd}`
      end_time = Time.now
      results[cmd] = end_time - start_time
    end
  end

  threads.each do |cmd, thread|
    thread.join
  end

  results.each do |cmd, time|
    puts "#{cmd}: #{time}"
  end
end