In Smalltalk, is there a way to search for all methods available (of any object), say, that contain the word convert
(case insensitive search), and also contain the word string
? (the method name, not the source code)
In Smalltalk you have direct access to all classes, their methods and their source code, so you can go through them.
Go over all the classes and then from each class select all methods that match your needs (or use the Finder tool).
Object withAllSubclasses flatCollect: [ :cls |
cls methods select: [ :method |
(method selector includesSubstring: 'convert' caseSensitive: false) and: [
(method selector includesSubstring: 'string' caseSensitive: false) ]
]
].
GST doesn't have as nice API, but it can be done also.
(Object withAllSubclasses collect: [ :cls |
cls methodDictionary ifNotNil: [ :dict |
dict values select: [ :method |
(method selector asLowercase indexOfSubCollection: 'convert' asLowercase) > 0 and: [
(method selector asLowercase indexOfSubCollection: 'string' asLowercase) > 0 ]
]
]
]) join
(also Pharo and Squeak, and with ifNotNil:
also GNU Smalltalk)
VW doesn't have #flatten
, so it's implemented explicitly. For case-insensitive search #findSameAs:startingAt:wildcard:
can also be used.
(Object withAllSubclasses collect: [ :cls |
cls methodDictionary values select: [ :method |
(method selector asLowercase findString: 'convert' asLowercase startingAt: 1) > 0 and: [
(method selector asLowercase findString: 'string' asLowercase startingAt: 1) > 0 ]
]
]) inject: #() into: [ :arr :each | arr, each ]
Dolphin seems to have different object model, see Leandro's answer below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With