I'm want to do meta programming in the sense of writing ruby to create
a new ruby method.
However modern ruby now has required parameters, default parameters,
required keyword parameters and optional keyword parameters and an
optional a block parameter.
So Method.parameters seems to understand all these things....
> def foo( bar, baz, but = 0, joke:, nojoke: 10, &block);end
=> [[:req, :bar], [:req, :baz], [:opt, :but], [:keyreq, :joke], [:key,
:nojoke], [:block, :block]]
Module#define_method would seem to be what I want.... but... that
defers the problem of specifying the parameters to Proc, Method,
UnboundMethod or block....
Proc.new basically converts a block into a Proc.
Method.new and UnboundMethod.new do not exist.
block's themselves are not quite first class objects.
I guess I could achieve the required magic by Module.class_eval(
string) ... but that seems crude...
Any idea how to define (at run time) the parameter list for a method?
I have done it, somewhat crudely by
define_method( :my_constructed_at_run_time_method) do
# Implement all the parameter checking and raise
ArgumentError in the right places
# in raw ruby...
..but that seems duplicating all the logic around parameter checking
that must already exist somewhere in the Ruby runtime..