Let's suppose I have a command written in Ruby, that is outputting to HTML in a new window.

Is there a way to create a link in the HTML output that, when clicked, will actually execute a Ruby function that I define in the command?

For example, something like:

def do_something(x)
    # do something with x
end

puts "<a href=\"command:do_something(42)\">Edit X</a>"

My end goal is to provide an interface for manipulating the current document; maybe the answer is to do the logic in JS within the HTML window, and then update the document from there, but I'm equally unsure of how to do that.