class MyWatir < Watir::Browser
def with_watir_window(win)
cw = window #current window
win.use
yield
cw.use
end
def qty
ret = nil
with_watir_window(@win2){
ret = td(:id,'qty').text
}
ret
end
end
In the second function, declaring ret = nil and stating it at the end seems ugly. Is there a cleaner way of returning the value?
Just return the inner value from the block. Also make sure that if an exception occurs, you leave in a consistent state: