Class: Sol::IRBObject
- Inherits:
-
Object
- Object
- Sol::IRBObject
- Defined in:
- lib/jx/irbobject.rb
Overview
An IRBObject is an “Internal” Ruby Object, i.e., is is created while executing a callback method that returns a Ruby Object and it stays inside a javascript script. This happens when a ruby block is passed as argument to a javascript function that expects a function as parameter. The block is converted to a javascript function in ruby_rich.rb by the call to:
// Makes a callback function from a given Ruby block
this.make_callback = function(blk) {
return function (...args) { blk.set_this(this); return blk.run("call", ...args); }
}
When this function is called, blk.run is called, which call Callback.run. In Callback.run the arguments are converted to ruby arguments. If the block returns a ruby Object, this Object is packed in a IRBObject.
Instance Attribute Summary collapse
-
#jsvalue ⇒ Object
readonly
Returns the value of attribute jsvalue.
-
#ruby_obj ⇒ Object
readonly
Returns the value of attribute ruby_obj.
Instance Method Summary collapse
-
#initialize(jsvalue) ⇒ IRBObject
constructor
————————————————————————————.
-
#is_instance_of(class_name) ⇒ Object
—————————————————————————————-.
-
#method_missing(symbol, *args, &blk) ⇒ Object
———————————————————————————— An IRBObject is called with ruby arguments, so it does not need to call any process_arguments method as it is proxies a Ruby object TODO: Might actually need to process_args on the argument since we use invoke BUG!!! ————————————————————————————.
-
#native(*args) ⇒ Object
————————————————————————————.
Constructor Details
#initialize(jsvalue) ⇒ IRBObject
82 83 84 85 86 |
# File 'lib/jx/irbobject.rb', line 82 def initialize(jsvalue) @jsvalue = jsvalue @run_func = @jsvalue.getProperty("run") @ruby_obj = @jsvalue.asJavaObject().ruby_obj end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &blk) ⇒ Object
An IRBObject is called with ruby arguments, so it does not need to call any process_arguments method as it is proxies a Ruby object TODO: Might actually need to process_args on the argument since we use invoke BUG!!!
103 104 105 106 |
# File 'lib/jx/irbobject.rb', line 103 def method_missing(symbol, *args, &blk) # B.invoke(@jsvalue, @run_func, symbol, *args) @ruby_obj.send(symbol, *args, &blk) end |
Instance Attribute Details
#jsvalue ⇒ Object (readonly)
Returns the value of attribute jsvalue.
44 45 46 |
# File 'lib/jx/irbobject.rb', line 44 def jsvalue @jsvalue end |
#ruby_obj ⇒ Object (readonly)
Returns the value of attribute ruby_obj.
45 46 47 |
# File 'lib/jx/irbobject.rb', line 45 def ruby_obj @ruby_obj end |
Instance Method Details
#is_instance_of(class_name) ⇒ Object
92 93 94 |
# File 'lib/jx/irbobject.rb', line 92 def is_instance_of(class_name) B.invoke(@jsvalue, @run_func, "is_instance_of", class_name) end |
#native(*args) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/jx/irbobject.rb', line 112 def native(*args) p "IRBObject native method. NOT WORKING YET!!" method = args.shift # other is a ruby object other = args.shift end |