module ZeroMQ
  module Errors
    ERRORS = Errno.constants.map(&Errno.method(:const_get)).
             inject({}) { |map, error| map[error.const_get(:Errno)] = error; map }

    private

    def check_result!(rc)
      return rc if ZMQ::Util.resultcode_ok?(rc)
      raise ERRORS.fetch(ZMQ::Util.errno) { ZMQ::Util.error_string }
    end
  end
end

module ZeroMQ
  module Errors
    ERRORS = Errno.constants.map(&Errno.method(:const_get)).
             select { |obj| obj.is_a?(Class) && obj < SystemCallError }.
             inject({}) { |map, error| map[error.const_get(:Errno)] = error; map }

    private

    def check_result!(rc)
      return rc if ZMQ::Util.resultcode_ok?(rc)
      raise ERRORS.fetch(ZMQ::Util.errno) { ZMQ::Util.error_string }
    end
  end
end

Select only the constants that are actually Errors
Select only the constants that are actually Errors

On Rubinius, there are a few other constants that end up under the Errno namespace (other than the myriad SystemCallError classes).

Ironically, one of these is Errno::Mapping, which ironically is there to serve the same purpose as the hash you're constructing here.

Anyway, adding this line will prevent the other constants from ending up in the inject block and raising an exception on Rubinius.