Class: R::RubyCallback
- Inherits:
-
Object
- Object
- R::RubyCallback
- Defined in:
- lib/R_interface/ruby_callback.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
The Ruby Proc, Method (or Object?) to be called back.
-
#r_function ⇒ Object
readonly
The R function that will call back on the object.
Class Method Summary collapse
-
.build(object) ⇒ Object
--------------------------------------------------------------------------------------.
Instance Method Summary collapse
-
#callback(*args) ⇒ Object
--------------------------------------------------------------------------------------.
-
#initialize(object) ⇒ RubyCallback
constructor
-------------------------------------------------------------------------------------- Initializes a callback object and constructs the R function that calls back the object.
-
#method_missing(symbol, *args) ⇒ Object
--------------------------------------------------------------------------------------.
Constructor Details
#initialize(object) ⇒ RubyCallback
Initializes a callback object and constructs the R function that calls back the object. RubyCallback class will act as proxy to the actual Ruby Object since it needs to deal with R parameters and Return values boxing and unboxing when needed
48 49 50 51 52 53 |
# File 'lib/R_interface/ruby_callback.rb', line 48 def initialize(object) @object = object # Use parse_arg to generate the R function that calls back this object's callback method @r_function = R::Support.parse_arg(method(:callback)) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
59 60 61 |
# File 'lib/R_interface/ruby_callback.rb', line 59 def method_missing(symbol, *args) p "in ruby_callback.rb method missing with #{symbol} #{args}" end |
Instance Attribute Details
#object ⇒ Object (readonly)
The Ruby Proc, Method (or Object?) to be called back
29 30 31 |
# File 'lib/R_interface/ruby_callback.rb', line 29 def object @object end |
#r_function ⇒ Object (readonly)
The R function that will call back on the object
31 32 33 |
# File 'lib/R_interface/ruby_callback.rb', line 31 def r_function @r_function end |
Class Method Details
.build(object) ⇒ Object
37 38 39 |
# File 'lib/R_interface/ruby_callback.rb', line 37 def self.build(object) RubyCallback.new(object).r_function end |
Instance Method Details
#callback(*args) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/R_interface/ruby_callback.rb', line 67 def callback(*args) # converts every arg into a R::Object (Ruby object that wraps an R Interop) args.map! { |arg| R::Object.build(arg) } # calls the callback method and convert the result back to an R object # method parse_arg was developed to parse the arguments to an R function # but in a callback the return value needs to be converted. In this case # the name parse_arg is misleading R::Support.parse_arg(@object.call(*args)) end |