Skip to content

Instantly share code, notes, and snippets.

@adelevie
Created September 7, 2012 00:31
Show Gist options
  • Save adelevie/3661895 to your computer and use it in GitHub Desktop.
Save adelevie/3661895 to your computer and use it in GitHub Desktop.
# 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