In Ruby, everything evaluates to true except false and nil. Also, the last statement executed is your return value. Therefore your first function could be written as
def delete_student(uid)
STUDENTS.remove(uid) || raise WebApplicationException.new(Response.Status.NOT_FOUND)
end
I have no idea what the annotations mean, but if we use exceptions for transmitting error conditions, then there is no point having a true | exception function.
public void deleteStudent(int uid) {
if (STUDENTS.remove(uid) == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
}
In that case it is preferable to use "or" over "||" since then you do not have to worry so much about operator precedence because "or" has about the weakest of all operators. This means in this case that you can skip the explicit ".new" for the exception.
def delete_student(uid)
STUDENTS.remove(uid) or raise WebApplicationException, Response.Status.NOT_FOUND
end