Last active
August 29, 2015 14:01
-
-
Save inger/07a1ce0973b41bdc3946 to your computer and use it in GitHub Desktop.
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
## jruby-users question "Overriding A Method For A Specific Instance" - | |
####### See: http://markmail.org/thread/emm5h6psqi4z3leq | |
## | |
#### Start this with jruby -rgdx.jar gdx_listener_hack.rb | |
### | |
#### where gdx is coming from http://libgdx.badlogicgames.com/releases/libgdx-1.0.1.zip | |
java_import "com.badlogic.gdx.scenes.scene2d.InputListener" | |
############### from email: | |
def listener_for(method, &block) | |
Class.new(InputListener) do | |
define_method(method, &block) | |
def initialize(mgr) | |
super() | |
@mgr = mgr | |
end | |
def create_method(name, &inner_block) | |
self.class.send(:define_method, name, &inner_block) | |
end | |
end.new(@mgr) | |
end | |
@inv_listener = listener_for(:touchDown) do |event, x, y, pointer, | |
button| | |
puts "starboard" | |
true | |
end | |
@inv_listener.create_method(:touchUp) do |event, x, y, pointer,button| | |
puts "stankboard" | |
true | |
end | |
# I can see that the method is being created by calling it: | |
#### Testing | |
puts "Calling touchUp..." | |
@inv_listener.touchUp(nil,nil) | |
puts "Calling touchDown..." | |
@inv_listener.touchDown(nil,nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment