Domanda

How to print the parameters of a specific method?

È stato utile?

Soluzione

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]

Altri suggerimenti

In Pharo3 it is even easier:

(Object>>#printOn:) argumentNames
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top