Skip to content

Instantly share code, notes, and snippets.

@Bodacious
Created April 1, 2014 20:00
Show Gist options
  • Save Bodacious/9921887 to your computer and use it in GitHub Desktop.
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 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