On Sun, Dec 4, 2011 at 9:57 AM, Chuck Remes <cremes.devlist / mac.com> wrote:

> On Dec 3, 2011, at 8:49 PM, Intransition wrote:
>
> > On Saturday, December 3, 2011 4:44:58 PM UTC-5, Chuck Remes wrote:
> > I should have waited a few more minutes. After typing this up, I was hit
> by inspiration. Here is my solution.
> >
> > I find writing an issue up often helps me figure out a problem, so it's
> not uncommon to post for some help and then figure it out a few minutes
> later.
> >
> > Maybe a good lesson in this -- write up the post, but give it a few
> minutes before actually sending it.
>
> Quite true. Perhaps my "thinking out loud" in public has been helpful for
> someone else too.
>
> I guess the technical term for this is "rubber ducking."
>
> cr
>
>
If it's not important to output the constructed string, you could do it
like this:

module Parameters
  module Base

    def self.create_each(mod, fields)
      fields.each do |field|
        mod.send(:define_method, "each_#{field}") do |&block|
          @params[field].each do |value|
            block.call(value)
          end
        end
      end
    end

    def self.create_combination(mod, fields)
      mod.send(:define_method, :each_combination) do |&block|
        head, *tail = @params.values_at(*fields)
        head.product(*tail, &block)
      end
    end

 end # Base
end # Parameters

You could use more tricks to avoid making the caller use create_combination
and create_each, but I'm not sure I know what your aim is.

pete