The Crystal Programming Language Forum

How do I fetch methods included from a module?

Hello everyone! If I’m not mistaken, @type.methods doesn’t seem to return defs included from a module, is there another way to fetch this list? Also TypeNode has includers but no includes (which could probably return all included modules), is this by design? Thanks!

Assuming you want a specific module, you could do MyModule.methods within a macro as well.

1 Like

@u89012 You can use ancestors to fetch all types in the upper hierarchy, including modules.

In general we added macro methods as experiments, like “oh, I wonder if we can have a method that returns all subclasses”, and so on. So a lot of methods are missing, but right now we decided to stop adding more methods until we sit down and think what we really want with all of this (or at least I won’t add or merge any PR that’s related to that).

@asterite Thank you, that’s what I’m using at the moment. I totally understand this needs to be tackled methodically. But just thinking out loud, I do wonder whether it would be easier to just ride on other work that came before, .NET has a great reflection package for example. Any chance there will be a includes macro that would do the opposite of includers?

@Blacksmoke16 Thanks for the link again! I’ll go with specifying the module name for now.