class Proxy
A proxy object that forwards method calls to a remote object.
We must be extremely careful not to invoke any methods on the proxy object that would recursively call the proxy object.
Definitions
def initialize(connection, name)
Create a new proxy object.
Signature
-
parameter
connectionConnection The connection to the remote object.
-
parameter
nameSymbol The name (address) of the remote object.
Implementation
def initialize(connection, name)
@connection = connection
@name = name
end
def __connection__
Get the connection to the remote object.
Signature
-
returns
Connection The connection to the remote object.
Implementation
def __connection__
@connection
end
def __name__
Get the name of the remote object.
Signature
-
returns
Symbol The name of the remote object.
Implementation
def __name__
@name
end
def !
Logical negation operator.
Signature
-
returns
Object The result of the negation.
Implementation
def !
@connection.invoke(@name, [:!])
end
def ==(object)
Equality operator.
Signature
-
parameter
objectObject The object to compare with.
-
returns
Boolean True if equal.
Implementation
def == object
@connection.invoke(@name, [:==, object])
end
def !=(object)
Inequality operator.
Signature
-
parameter
objectObject The object to compare with.
-
returns
Boolean True if not equal.
Implementation
def != object
@connection.invoke(@name, [:!=, object])
end
def method_missing(*arguments, **options, &block)
Forward method calls to the remote object.
Signature
-
parameter
argumentsArray The method arguments.
-
parameter
optionsHash The keyword arguments.
-
yields
{|*args| ...} Optional block to pass to the method.
-
returns
Object The result of the method call.
Implementation
def method_missing(*arguments, **options, &block)
@connection.invoke(@name, arguments, options, &block)
end
def respond_to?(name, include_all = false)
Check if the remote object responds to a method.
Signature
-
parameter
nameSymbol The method name to check.
-
parameter
include_allBoolean Whether to include private methods.
-
returns
Boolean True if the method exists.
Implementation
def respond_to?(name, include_all = false)
@connection.invoke(@name, [:respond_to?, name, include_all])
end
def inspect
Return a string representation of the proxy.
Signature
-
returns
String A string describing the proxy.
Implementation
def inspect
"#<proxy #{@name}>"
end