Feature #9553

Make argument validation routine of a method an object

Added by Boris Stitnicky over 1 year ago. Updated over 1 year ago.

[ruby-core:60995]
Status:Open
Priority:Normal
Assignee:-

Description

Ruby methods have their acceptable argument configurations specified by special syntax. As argument fields has gotten more complex, simple #arity is no longer enough to capture the type of the argument field. I suggest making this argument validation routine (so far defined by special syntax) introspectible, and reusable for the purposes of metaprogramming. One possibility would be to have eg. ArgumentValidator and/or UnboundArgumentValidator objects just like we have method and unbound method objects. Then eg. Method#argity / Proc#argity would return that ArgumentValidator or UnboundArgumentValidator. The purpose of this post is not to suggest the final solution, but to bring attention to the problem of non-oo nature of built-in argument validation and the growing need to do something about that.

History

#1 Updated by Charlie Somerville over 1 year ago

Does Method#parameters not solve your problem?

#2 Updated by Boris Stitnicky over 1 year ago

It is my fault that I was not aware of Method#parameters when writing this post. Too bad I did not participate in its naming, I would push for calling it Method#arguments. This method resolves the main reasons that led me to writing this post. It remains worthy of consideration to make #parameters method return a special object rather than just Array, but this thread can be closed without harm. Contrary to what I thought, the pressing part of the problem has already been tackled.

#3 Updated by Boris Stitnicky over 1 year ago

Even more precisely, I did not fail to notice, but rather forgot about it =). In any case, built in Arguments object would be nice.

Also available in: Atom PDF