是_a? 和 dRuby 对象
我正在使用 dRuby,基本上我正在调用一个远程方法来返回一个对象。
在客户端我有这样的代码:
handle_error(response) if response.is_a?(Error)
其中响应是 DRbObject。 (我在使用 dRuby 之前开发了这段代码,如果出现问题,我将返回一个 Error 对象)。 问题是现在
response.is_a?(Error)
返回“false”,因为该对象实际上是 DRbObject。 关于如何检查我的应用程序对象的类有什么想法吗?
谢谢! 罗伯托
I'm working with dRuby and basicly I'm calling a remote method that returns me an object.
In the clientside I have this code:
handle_error(response) if response.is_a?(Error)
where response is the DRbObject. (I've developed this code before using dRuby and I'm returning an Error object if something went wrong). The problem is that now
response.is_a?(Error)
comes back with "false" because the object is actually a DRbObject.
Any idea on how I can check the class of my application object?
Thanks!
Roberto
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(2)
虽然我不确定 DRb 如何管理远程对象,但我希望它能修改 #kind_of? 将类层次结构保留在远程对象上,因此您可以这样做:
如果这不起作用,您可以随时询问它是否响应特定方法并从那里开始
Although I'm not sure how DRb manages the remote objects, I'd expect it to modify #kind_of? to keep the class hierarchy on the remote object, so you could do:
If this doesn't work you can always ask it if it responds to an specific method and go from there
您不能使用 Duck 解决该问题吗正在输入? 检查对象是否响应调用以获取错误信息,而不是检查对象是否为错误。 如果是,则根据该信息处理错误,否则处理(非错误)响应。
Could you not work around the problem by using Duck Typing? Instead of checking for whether the object is an Error, check whether the object responds to a call to get the error information. If it does, handle the error according to that information, otherwise handle the (non-error) response.