Created
September 7, 2012 00:31
-
-
Save adelevie/3661895 to your computer and use it in GitHub Desktop.
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
| # RubyMotion doesn't seem to support using subclasses to override methods from Objective-C classes. | |
| # Here's probably an awful way to achieve the effect of subclassing: | |
| class AlanView | |
| def init | |
| @uiview = UIView.alloc.init | |
| self | |
| end | |
| def addSubview(view) | |
| fakeSuper = @uiview.addSubview(view) | |
| puts "I can extend functionality here" | |
| fakeSuper | |
| end | |
| def method_missing(method, *args, &block) | |
| @uiview.send(method, *args, &block) | |
| end | |
| def self.method_missing(method, *args, &block) | |
| UIView.send(method, *args, &block) | |
| end | |
| end | |
| # usage: | |
| mySubview = UIView.alloc.init | |
| myAlanView = AlanView.alloc.init | |
| myAlanView.addSubview(mySubview) #=> "I can extend functionality here" | |
| AlanView.layerClass #=> CALayer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment