Asan
Asan

Reputation: 199

Getting a method parameters in Smalltalk

How to print the parameters of a specific method?

Upvotes: 2

Views: 884

Answers (2)

MarcusDenker
MarcusDenker

Reputation: 61

In Pharo3 it is even easier:

(Object>>#printOn:) argumentNames

Upvotes: 1

David Buck
David Buck

Reputation: 2847

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]

Upvotes: 1

Related Questions