Is there a way to change mainWindow on appium?

Im using ruby lib, and, for example, when I want a button by its name, I call it this way:

buttons'name of the button'

but sometimes mainWindow 0 is nil, and the button is not found, but if appium checked the windows before call it, it could change to mainWindow 1, where the button can be found

Is there a way to set it?