Created
November 10, 2012 23:15
-
-
Save workwithnano/4052921 to your computer and use it in GitHub Desktop.
Calling define_method in RubyMotion Module (v 1.27)
This file contains 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
module MTFGestures | |
def gestureRecognizerWithCompletionBlock( gestureClassString, target, completion ) | |
case gestureClassString | |
when "UIPanGestureRecognizer" then | |
# Define the panning delegate method based | |
# on the completion handler passed to this | |
# function. | |
define_method "panning" do |sender| | |
completion( sender ) | |
end | |
# Create the pan gesture recognizer and | |
# send it along to our fake delegate method | |
panGestureRecognizer = UIPanGestureRecognizer.alloc.initWithTarget( target, action:"panning" ) | |
self.view.addGestureRecognizer( panGestureRecognizer ) | |
else | |
raise "#{gestureClassString} is not a supported gesture yet." | |
end | |
end | |
end |
An error occurs when define_method is called:
mtf_gestures.rb:12:in gestureRecognizerWithCompletionBlock:': undefined method
define_method' for #MTFDuoViewController:0x9d0a0b0 (NoMethodError)
MTFDuoViewController is the Class which calls "include MTFGestures"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This module is included in another class. It's not used as a static-method Module.