class WWW::Mechanize

def submit(form, button=nil)

agent.submit(page.forms.first, page.forms.first.buttons.first)
With a button
agent.submit(page.forms.first)
page = agent.get('http://example.com')
Without a button:
Submit a form with an optional button.
def submit(form, button=nil)
  form.add_button_to_query(button) if button
  case form.method.upcase
  when 'POST'
    post_form(form.action, form)
  when 'GET'
    get(  :url      => form.action.gsub(/\?[^\?]*$/, ''),
          :params   => form.build_query,
          :referer  => form.page
       )
  else
    raise "unsupported method: #{form.method.upcase}"
  end
end