Method: Calculator#div

Defined in:
src/ruby/bin/math_server.rb

#div(div_args, _call) ⇒ Object

[View source]

97
98
99
100
101
102
103
104
105
106
107
# File 'src/ruby/bin/math_server.rb', line 97

def div(div_args, _call)
  if div_args.divisor.zero?
    # To send non-OK status handlers raise a StatusError with the code and
    # and detail they want sent as a Status.
    fail GRPC::StatusError.new(GRPC::Status::INVALID_ARGUMENT,
                               'divisor cannot be 0')
  end

  Math::DivReply.new(quotient: div_args.dividend / div_args.divisor,
                     remainder: div_args.dividend % div_args.divisor)
end