Created
April 1, 2014 20:00
-
-
Save Bodacious/9921887 to your computer and use it in GitHub Desktop.
Rubymotion developers often seem to shy away from using getter methods for instance variables. Instead, they're defined all over the place - as you'd see more in Objective-C.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is the approach I see most commonly in Rubymotion code examples. | |
class AppDelegate | |
def application(application, didFinishLaunchingWithOptions:launchOptions) | |
@mainViewController = MainViewController.alloc.init | |
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame) | |
@window.rootViewController = mainViewController | |
@window.makeKeyAndVisible | |
true | |
end | |
end | |
# In my opinion, this approach is cleaner and is more idiomatic OO Code. | |
class AppDelegate | |
def mainViewController | |
@mainViewController ||= MainViewController.alloc.init | |
end | |
def window | |
@window ||= UIWindow.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame) | |
end | |
def application(application, didFinishLaunchingWithOptions:launchOptions) | |
window.rootViewController = mainViewController | |
window.makeKeyAndVisible | |
true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment