How to get the compiled method the is being execut

2019-05-10 02:29发布

How to get an instance of CompiledMethod that is currently being executed?

i.e.

someMethod
  | thisMethod |
  thisMethod := "here I want to access an instance of _CompiledMethod_ that refers to #someMethod".
  ^ thisMethod selector

1条回答
干净又极端
2楼-- · 2019-05-10 02:51

Method that is currently being executed can be retrieved by #method message from current context, which can be accessed through thisContext pseudo variable.

This way example code will look like this:

someMethod
  | thisMethod |
  thisMethod := thisContext method.
  ^ thisMethod selector
查看更多
登录 后发表回答