Module: Processing::Proxy
- Defined in:
- lib/ruby-processing/app.rb
Overview
This module will get automatically mixed in to any inner class of a Processing::App, in order to mimic Java’s inner classes, which have unfettered access to the methods defined in the surrounding class.
Class Method Summary collapse
-
.desired_method_names ⇒ Object
Generate the list of method names that we’d like to proxy for inner classes.
-
.included(inner_class) ⇒ Object
Don’t do all of the work unless we have an inner class that needs it.
-
.proxy_constants ⇒ Object
Proxy the sketch’s constants on to the inner classes.
-
.proxy_methods ⇒ Object
Proxy methods through to the sketch.
Class Method Details
.desired_method_names ⇒ Object
Generate the list of method names that we’d like to proxy for inner classes. Nothing camelCased, nothing __internal__, just the Processing API.
451 452 453 454 455 456 457 |
# File 'lib/ruby-processing/app.rb', line 451 def self.desired_method_names bad_method = /__/ # Internal JRuby methods. unwanted = PApplet.superclass.instance_methods + Object.instance_methods unwanted -= ['width', 'height'] methods = Processing::App.public_instance_methods methods.reject {|m| unwanted.include?(m) || bad_method.match(m) } end |
.included(inner_class) ⇒ Object
Don’t do all of the work unless we have an inner class that needs it.
482 483 484 485 486 487 |
# File 'lib/ruby-processing/app.rb', line 482 def self.included(inner_class) return if @already_defined proxy_methods proxy_constants @already_defined = true end |
.proxy_constants ⇒ Object
Proxy the sketch’s constants on to the inner classes.
474 475 476 477 478 |
# File 'lib/ruby-processing/app.rb', line 474 def self.proxy_constants Processing::App.constants.each do |name| Processing::Proxy.const_set(name, Processing::App.const_get(name)) end end |
.proxy_methods ⇒ Object
Proxy methods through to the sketch. Perhaps extend this to support blocks?
461 462 463 464 465 466 467 468 469 470 |
# File 'lib/ruby-processing/app.rb', line 461 def self.proxy_methods code = desired_method_names.inject('') do |code, method| code << <<-EOS def #{method}(*args) # def rect(*args) $app.#{method} *args # $app.rect *args end # end EOS end module_eval(code, "Processing::Proxy", 1) end |