ruby 中的发送器类? [英] sender class in ruby?

查看:48
本文介绍了ruby 中的发送器类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何在 ruby​​ 中获取发送者类/模块吗?

Anyone know how to get the sender class/module in ruby?

caller[0] 有助于导出文件名和行号发送.

caller[0] is helpful to derive the filename and linenumber sending.

但是了解课程会有所帮助.找不到任何搜索?

But knowing the class would be helpful. Can't find it any searches?

推荐答案

这是不可能的.无论如何,您不应该在基于调用类的方法中专门化您的行为.

This would be impossible. You shouldn't be specialising your behaviour in a method based on the calling class anyway.

这样想 - 调用者可以是一个在一个类中创建的匿名函数 (proc),然后交给另一个类并从第三个地方调用.你不会得到任何有用的东西.

Think about it this way - the caller could be an anonymous function (proc) created in one class, then given to another one and invoked from a third place. You wouldn't get anything useful.

相反,我会看看您在这里尝试实现的目标,并想出另一种方法来实现目标!:)

Instead, I'd look at what you're trying to achieve here, and think of another way to get there! :)

这篇关于ruby 中的发送器类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆