I would like to check if a particular class has been loaded.
Smalltalk at: #TabularXSLXExport ifNone: [ ]
This does not lead to a result in Pharo. How do I do this?
I think the method you're looking for is #at:ifAbsent: (not #at:ifNone:).
So, inspecting the result of
Smalltalk at: #String ifAbsent: [ nil ]
will let you inspect the String class, while
Smalltalk at: #Strign ifAbsent: [ nil ]
will open an inspector on nil (note that "Strign" is a deliberate misspelling of "String" so that the lookup fails).
Edit: As Max Leske points out in the comments, #hasClassNamed: is a more suitable method if you're just trying to determine whether the class exists, and not interested in the class itself being returned.
You might want to do an extension method for this, or use a pragma to collect all 'exports', or register this functionality. The world menu uses a pragma <worldMenu>.Catalog browser uses it like this:
CatalogBrowser class>>menuCommandOn: aBuilder
"Add a custom menu item to the world menu"
<worldMenu>
(aBuilder item: #'Catalog Browser')
order: 0.19;
icon: Smalltalk ui icons catalogIcon;
parent: #'Tools';
action: [ self open ].
Take a look at PragmaMenuBuilder for how that works
In Pharo4 that is the MetacelloConfigurationBrowser:
MetacelloConfigurationBrowser class>>menuCommandOn: aBuilder
<worldMenu>
(aBuilder item: 'Configuration Browser')
parent: #Tools;
order: 0.20;
action: [self new openWithSpec];
icon: Smalltalk ui icons configIcon
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