class SystemCall::Result

A class that represents a result of a system call.

@!attribute [r] exit_status

@return [Process::Status] The exit status of the result.

@!attribute [r] success_result

@return [String] The STDOUT of the result.

@!attribute [r] error_result

@return [String] The STDERR of the result.

Attributes

error_result[R]
exit_status[R]
success_result[R]

Public Class Methods

new(exit_status, success_result, error_result) click to toggle source

Initializes a new {Result}.

@param exit_status [Process::Status] The exit status of the result. @param success_result [String] The STDOUT of the result. @param error_result [String] The STDERR of the result.

# File lib/system_call/result.rb, line 24
def initialize(exit_status, success_result, error_result)
  @exit_status = exit_status
  @success_result = success_result
  @error_result = error_result
end

Public Instance Methods

<=>(other) click to toggle source

Compares the result with the result of {#to_s} from another object.

@param other [#to_s, nil] @return [Integer, nil]

# File lib/system_call/result.rb, line 70
def <=>(other)
  return nil if other.nil?

  result <=> other.to_s
end
error?() click to toggle source

Indicates whether the command has not been executed successfully.

@return [Boolean]

# File lib/system_call/result.rb, line 50
def error?
  !success?
end
exit_code() click to toggle source

Gets the exit code of the process.

@return [Integer]

# File lib/system_call/result.rb, line 34
def exit_code
  exit_status.exitstatus
end
result() click to toggle source

Returns the command result.

@return [String] Returns result from {#success_result} when command exited

successfully. Otherwise returns result from {#error_result}.
# File lib/system_call/result.rb, line 59
def result
  success? ? success_result : error_result
end
Also aliased as: to_s
success?() click to toggle source

Indicates whether the command has been executed successfully.

@return [Boolean]

# File lib/system_call/result.rb, line 42
def success?
  exit_status.success?
end
to_s()
Alias for: result