Skip to content

Instantly share code, notes, and snippets.

@riethmayer
Created January 20, 2010 19:49
Show Gist options
  • Save riethmayer/282169 to your computer and use it in GitHub Desktop.
Save riethmayer/282169 to your computer and use it in GitHub Desktop.
bouncer method
# Method whose job is to raise or do nothing
def check_child_exit_status
result = yield
status = $? || OpenStruct.new(:exitstatus => 0)
unless [0,172].include?(status.exitstatus)
raise ArgumentError,
"Command exited with status #{status.exitstatus}"
end
result
end
# Before:
@io_class.popen(command, "w+") # ...
# ...
if $? && ![0,172].include?($?.exitstatus)
raise ArgumentError,
"Command exited with status #{$?.exitstatus.to_s}"
end
# After:
check_child_exit_status {
@io_class.popen(command, "w+") # ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment