How to print the parameters of a specific method?

有帮助吗?

解决方案

Parameters don't have types so you can't print those. It seems that you want to print the method header which provides the name of the method and the names of the parameters. You already have the name of the method so you need to get the names of the parameters. The only way to get the names of the parameters is from the original source string. Here's a nice way to extract the parameter names from the source string. In this example, I'm getting the name of the parameter of the printOn: method in class Object.

(Parser new parse: (Object sourceCodeAt: #printOn:) class: Object) arguments
  collect: [:each | each name]

其他提示

In Pharo3 it is even easier:

(Object>>#printOn:) argumentNames
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top