module Validate::Arguments::ClassMethods
Public Instance Methods
arg(name, &body)
click to toggle source
# File lib/validate/arguments.rb, line 14 def arg(name, &body) if @args.include?(name) raise Error::ArgumentError, "duplicate argument :#{name}" end @args[name] = Assertions.create(&body) self end
method_added(method_name)
click to toggle source
Calls superclass method
# File lib/validate/arguments.rb, line 4 def method_added(method_name) super guard_method(instance_method(method_name), @methods_guard) end
singleton_method_added(method_name)
click to toggle source
Calls superclass method
# File lib/validate/arguments.rb, line 9 def singleton_method_added(method_name) super guard_method(singleton_method(method_name), @singleton_methods_guard) end
Private Instance Methods
guard_method(method, guard_module)
click to toggle source
Calls superclass method
# File lib/validate/arguments.rb, line 25 def guard_method(method, guard_module) return if @args.empty? guard = ArgumentsGuard.new(method, @args) guard_module.__send__(:define_method, method.name) do |*args, **kwargs, &block| if kwargs.empty? guard.enforce!(*args, &block) super(*args, &block) else guard.enforce!(*args, **kwargs, &block) super(*args, **kwargs, &block) end end ensure @args = {} end