I have a function that presents the user a combo-box.
def select_interface(interfaces) list_box :items => interfaces do |list| interface = list.text end ### ideally should wait until interface has a value then: ### return interface end
The rest of the program depends on the selection from this combo-box.
I would like to find a way to make ruby wait for the input from the combo-box and then carry executing the rest of the code.
There is a similar function in shoes called ask that will wait for the input of the user.
interface = ask('write your interface here')
How can I implement this ‘wait until the variable has a value’ function in Ruby/shoes?
It took me a while to understand your question 🙂 I started writing a long answer about the entire theory of GUI applications. But you already have everything you need. The block that list_box takes is really its change method. You’re telling it what to do when it gets changed. Just defer the rest of the program to run when you get a value you want.
This is the basic idea behind all GUI applications: build the initial application then wait for ‘events’, which will create new states for you respond to. In ruby-gnome2, for example, you would use a callback function/block with a Gtk::ComboBox that would change the state of your application. Something like this:
Even outside of a toolkit you can get a ‘free’ events system using Ruby’s Observer module. Hope this helped.