سؤال

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