Class: Culerity::RemoteObjectProxy
- Inherits:
-
Object
- Object
- Culerity::RemoteObjectProxy
- Defined in:
- lib/culerity/remote_object_proxy.rb
Direct Known Subclasses
Instance Method Summary collapse
- #exit ⇒ Object
-
#id ⇒ Object
Commonly used to get the HTML id attribute Use ‘object_id` to get the local objects’ id.
-
#initialize(remote_object_id, io) ⇒ RemoteObjectProxy
constructor
A new instance of RemoteObjectProxy.
- #method_missing(name, *args) ⇒ Object
-
#send_remote(name, *args, &blk) ⇒ Object
Calls the passed method on the remote object with any arguments specified.
Constructor Details
#initialize(remote_object_id, io) ⇒ RemoteObjectProxy
Returns a new instance of RemoteObjectProxy.
11 12 13 14 |
# File 'lib/culerity/remote_object_proxy.rb', line 11 def initialize(remote_object_id, io) @remote_object_id = remote_object_id @io = io end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
24 25 26 |
# File 'lib/culerity/remote_object_proxy.rb', line 24 def method_missing(name, *args) send_remote(name, *args) end |
Instance Method Details
#exit ⇒ Object
43 44 45 |
# File 'lib/culerity/remote_object_proxy.rb', line 43 def exit @io << '["_exit_"]' end |
#id ⇒ Object
Commonly used to get the HTML id attribute Use ‘object_id` to get the local objects’ id.
20 21 22 |
# File 'lib/culerity/remote_object_proxy.rb', line 20 def id send_remote(:id) end |
#send_remote(name, *args, &blk) ⇒ Object
Calls the passed method on the remote object with any arguments specified. Behaves the same as Object#send
.
If you pass it a block then it will append the block as a “lambda { … }”. If your block returns a lambda string (“lambda { … }”) then it will be passed straight through, otherwise it will be wrapped in a lambda string before sending.
36 37 38 39 40 41 |
# File 'lib/culerity/remote_object_proxy.rb', line 36 def send_remote(name, *args, &blk) input = [remote_object_id, %Q{"#{name}"}, *args.map{|a| a.inspect}] input << block_to_string(&blk) if block_given? @io << "[#{input.join(", ")}]\n" process_result @io.gets.to_s.strip end |