Command-line programs report success or failure with an exit status code.

Exit Status Model

exit_status_model.rb
valid = 
warnings = 

status = if !valid
  1
elsif warnings > 0
  2
else
  0
end

meaning = case status
when 0
  "success"
when 1
  "error"
else
  "warning"
end

puts "valid=#{valid}"
puts "warnings=#{warnings}"
puts "status=#{status}"
puts "meaning=#{meaning}"
valid = 
warnings = 

status = if !valid
  1
elsif warnings > 0
  2
else
  0
end

meaning = case status
when 0
  "success"
when 1
  "error"
else
  "warning"
end

puts "valid=#{valid}"
puts "warnings=#{warnings}"
puts "status=#{status}"
puts "meaning=#{meaning}"
valid = 
warnings = 

status = if !valid
  1
elsif warnings > 0
  2
else
  0
end

meaning = case status
when 0
  "success"
when 1
  "error"
else
  "warning"
end

puts "valid=#{valid}"
puts "warnings=#{warnings}"
puts "status=#{status}"
puts "meaning=#{meaning}"
valid = 
warnings = 

status = if !valid
  1
elsif warnings > 0
  2
else
  0
end

meaning = case status
when 0
  "success"
when 1
  "error"
else
  "warning"
end

puts "valid=#{valid}"
puts "warnings=#{warnings}"
puts "status=#{status}"
puts "meaning=#{meaning}"
valid = 
warnings = 

status = if !valid
  1
elsif warnings > 0
  2
else
  0
end

meaning = case status
when 0
  "success"
when 1
  "error"
else
  "warning"
end

puts "valid=#{valid}"
puts "warnings=#{warnings}"
puts "status=#{status}"
puts "meaning=#{meaning}"
valid = 
warnings = 

status = if !valid
  1
elsif warnings > 0
  2
else
  0
end

meaning = case status
when 0
  "success"
when 1
  "error"
else
  "warning"
end

puts "valid=#{valid}"
puts "warnings=#{warnings}"
puts "status=#{status}"
puts "meaning=#{meaning}"
exit status Ruby programs can compute a status code before passing it to `exit`; examples can model the value without ending the replay early.