1. Home
  2. Computing & Technology
  3. Ruby

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

By Amanda & Michael Morin, About.com

3 of 5

Asking for Confirmation

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
Explore Ruby
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Ruby
  4. GUI
  5. Shoes
  6. Asking for Confirmation

©2009 About.com, a part of The New York Times Company.

All rights reserved.