RubyMotion comes with an interactive console that lets us traverse and scan the code that we are using in our application. The good thing is that the console is connected to the application running on the simulator. This means that if we make any changes from the console, it will be reflected on the simulator in real time. Let's try this with our HelloWorld application.
Run the application as follows:
$rake
As expected, it will open a simulator and the terminal screen will show:
(main)>
Now hold the Command key and hover the mouse over the simulator. You will see a red-bordered box. As we move the mouse pointer over an element, we can see its corresponding class object appearing in the terminal window (UIView:0xc5710c0)? as seen in the following screenshot. Now click the mouse to select the object that you want to work on dynamically.
Try the following command on the terminal and observe the changes in the simulator:
self returns the current object selected by the mouse.
(#<UIView:0x7652680>)> self=> #<UIView:0x7652680>
Create an object blue for the UIColor class and assign the color blue to the variable as follows:
(#<UIView:0x7652680>)> blue = UIColor.blueColor
To change the background color of the view, use the backgroundColor property of the selected view as follows:
Make sure that the background color on the simulator has been changed to blue as shown in the following screenshot:
Let's dismiss the alert box by clicking on any button and put a new alert box with the following code:
a = UIAlertView.new
a.title = "My Title"
a.message = "Hello World!"
a.show
The simulator shows a new alert box on screen without compiling the code as shown in the following screenshot:
You can dismiss the alert box as follows:
(main) > a.dismiss
We can see how REPL is a great tool for developing applications for iOS and how it helps us make changes dynamically. To make these changes permanent we need to add the same code to our source code.