Method: ProcessShared::PosixCall#error_check
- Defined in:
- lib/process_shared/posix_call.rb
#error_check(*syms, &is_err) ⇒ Object
Replace methods in syms with error checking wrappers that invoke the original method and raise a SystemCallError with the current errno if the return value is an error.
Errors are detected if the block returns true when called with the original method’s return value.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/process_shared/posix_call.rb', line 11 def error_check(*syms, &is_err) unless block_given? is_err = lambda { |v| (v == -1) } end syms.each do |sym| method = self.method(sym) define_singleton_method(sym) do |*args| ret = method.call(*args) if is_err.call(ret) raise SystemCallError.new("error in #{sym}", LibC.errno) else ret end end end end |