1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Are You Sure You Want to Exit? and Other Dialog Methods

By

3 of 5

Asking for Confirmation
Are You Sure You Want to Exit? and Other Dialog Methods

We've all come across the next method at one time or another and while in some cases it can be annoying, it's actually a very helpful failsafe. The confirm method is that which displays "Are you sure?" type dialog boxes with OK and Cancel buttons. You can use this to ask things like the ubiquitous Are you sure you want to delete that file? or the ever-presentAre you sure you want to exit? questions. Combined with an if statement, this is a simple and expressive dialog.

Shoes.app :width => 200, :height => 100 do
  button "Click me" do
    if confirm("Add a new line of text?")
      @box.append para("New line of text\n")
    end
  end

  @box = stack
end
  1. About.com
  2. Technology
  3. Ruby
  4. Graphical User Interfaces
  5. Shoes
  6. Asking for Confirmation

©2014 About.com. All rights reserved.