check and reject nil arguments

Run Settings
LanguageRuby
Language Version
Run Command
# coding: utf-8 # [debug] check nil arguments, reject them if needed module NilArgs Module.include self NilArgsHookedMethods = {} def nilargs sym old = instance_method sym NilArgsHookedMethods[self] ||= {} raise NameError if NilArgsHookedMethods[self][sym] NilArgsHookedMethods[self][sym] = true define_method sym do |*args, &blk| if args.any?(&:nil?) call = "#{self}.#{sym}(#{args.map(&:inspect).join(', ')})" puts "[debug#nilargs] #{call}" else old.bind(self).call(*args, &blk) end end rescue old = method sym define_singleton_method sym do |*args, &blk| if args.any?(&:nil?) call = "#{self}.#{sym}(#{args.map(&:inspect).join(', ')})" puts "[debug#nilargs] #{call}" else old.call(*args, &blk) end end end end class A nilargs def self.add(a, b) a + b end nilargs def add(a, b) a + b end end A.new.add 1, nil # [debug#nilargs] #<A:0x00000000050ae100>.add(1, nil) A.add nil, 2 # [debug#nilargs] A.add(nil, 2)
Editor Settings
Theme
Key bindings
Full width
Lines