Using the RubyMotion REPL with VoiceOver
The Ruby programming language has a cool feature called the REPL, or Read Eval Print Loop. It allows entering expressions and seeing their results in real time. This can help test a program. If something doesn’t work you can enter expressions to try to narrow down the problem. You can also just have fun and tinker.
RubyMotion brings this same great capability to the iOS world. This lets you modify aspects of your application while it runs in a simulator. You can change the properties of a view and do any number of cool things. Many people consider it one of RubyMotion’s strongest advantages over Objective C.
In my talk at #inspect, I stated that the blind cannot use the REPL. Technically speaking, we can use the REPL, we can’t use the iOS simulator. This basically made it useless, since the simulator made it possible to navigate the app… or so I thought.
After I came back from Belgium I felt inspired to dive into RubyMotion, of course. I explored a lot of gems, including SugarCube. I had already started using it, but ignored the part about the REPL. Now I had another look and discovered the “tree” method. It lists all the current subviews in the current view. The “adjust” or “a” method selects a subview by number. And “a” by itself returns the currently selected subview.
Now I just needed to figure out a way to tap a button. I asked on the mailing list, and someone replied and suggested using the UIButton.sendActionsForControlEvents: method. Sure enough, typing
a.sendActionsForControlEvents(UIControlEventTouchUpInside)
worked. I whipped up a quick test method and it also worked. SugarCube also allows :touch.uibutton for easier reference.
I posted about my progress, and to my delight Colin added this feature to SugarCube. Now after selecting a view you can just type
a.trigger :touch
and like magic it will tap the button in the REPL. This makes it possible for me to use it, something I thought impossible only a month ago. I feel ecstatic.
This rapid feedback loop shows the strength of the RubyMotion community. In a very short time we added a great feature to a gem which will help everyone. It also totally opens the door to greater productivity for any blind developers. I said it in my talk and I’ll say it again here: the future looks very good for RubyMotion!