Class: EacRubyUtils::Envs::Spawn
- Defined in:
- lib/eac_ruby_utils/envs/spawn.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
-
#initialize(command) ⇒ Spawn
constructor
A new instance of Spawn.
- #kill(signal) ⇒ Object
- #kill_at_end(&block) ⇒ Object
- #to_h ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(command) ⇒ Spawn
Returns a new instance of Spawn.
8 9 10 11 |
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 8 def initialize(command) @command = command @pid = ::Process.spawn(command) end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 6 def command @command end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
6 7 8 |
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 6 def pid @pid end |
Instance Method Details
#kill(signal) ⇒ Object
13 14 15 |
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 13 def kill(signal) ::Process.kill(signal, pid) end |
#kill_at_end(&block) ⇒ Object
17 18 19 20 21 |
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 17 def kill_at_end(&block) block.call(self) ensure kill('KILL') end |
#to_h ⇒ Object
23 24 25 |
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 23 def to_h { command: command, pid: pid } end |
#wait ⇒ Object
27 28 29 |
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 27 def wait ::Process.wait pid end |