Pergunta

How to print the parameters of a specific method?

Foi útil?

Solução

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]

Outras dicas

In Pharo3 it is even easier:

(Object>>#printOn:) argumentNames
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top