Another way for Htmldialog get_element_value. Need Help

His code is based upon my example (in this thread.)

It would be a messy example if it used one method.

I chose for this example, to use a “trigger” method, 1 callback that receives the value, and a separate method that can process any of the values in the @values hash.

Asside: I know, you could actually have the value parameter optional, and then have a conditional inside the method, and then 1 arg makes it a “trigger” and 2 args and it is being called from the dialog’s JS.
But this is not as simple an example as I show above.

In my example I choose to have the “receive_value()” method first quickly assign the value to a hash (whose keys are id strings,) and then call a separate “process_value()” method, because it may likely be needed to have other methods initiate the processing of values at other times than when a dialog receives a value. (Such as triggered by a API observer, etc.)

It also occured to me that sometime, it may be advantageous to iterate the @values hash and process all values. This again makes sense to have the process routine in a separate method than the receive callback from JS.

EDIT: I’ve added a process iterator method to the example to illustrate this point …

    def process_values
      @values.keys.each { |id| process_value(id) }
    end

However, if you have a better idea / example, PLEASE post it rather than tearing mine down.