1. Home
  2. Computing & Technology
  3. Ruby

Edit Boxes

By , About.com Guide

1 of 3

Basic Usage

In our article about displaying text and paragraphs in Shoes, we discussed how the World Wide Web and HTML heavily influenced the GUI. In keeping with Shoes' parallel to HTML, there are two primary ways of displaying an edit box. The first method is the single line edit box, which is created by the edit_line method. The object returned by this method (usually stored in an instance variable) can be used to read the text in the edit box at any time.

Shoes.app :width => 400, :height => 340 do
  flow do
    @e = edit_line
    button "Go!" do
      alert @e.text
      @e.text = ''
    end
  end
end

You'll noticed that in the above example, the edit_line object is stored in the instance variable @e. When the button is pressed, the alert method is passed the text from @e. After the alert method is finished, the text is set to the empty string, essentially clearing the edit_line.

Explore Ruby
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

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

  1. Home
  2. Computing & Technology
  3. Ruby
  4. GUI
  5. Shoes
  6. Edit Boxes

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

All rights reserved.