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 54 |
# File 'lib/R_interface/ruby_callback.rb', line 48 def initialize(object) @object = object # ruby_callback_method is a method that returns an R function that returns an R # function that calls back this object callback method (look at callback bellow) @r_function = R::Support.ruby_callback_method.call(method(:callback)) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
60 61 62 |
# File 'lib/R_interface/ruby_callback.rb', line 60 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
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/R_interface/ruby_callback.rb', line 68 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 |