Open vifreefly opened 5 years ago
Hey.
Thanks for the suggestion.
At the moment it won't be possible to have, because Crystal does not have such reflection mechanisms like Ruby has, e.g. methods, like Object#methods
, Object#instance_variables
, etc.
I'll close the issue for now. Please reopen it, if you have an idea how this could be achieved.
@greyblake please re-open, it's possible with macros!
Something like ls String
could do a pp {{ String.methods.map(&.name.stringify) }}
to list all methods name.
It's a very basic example, but you can get other information on each method (it's signature, body, etc..) with some more macro code :)
Doing some ruby now, and actually used ls
on an ActiveRecord object, it's pretty cool in pry!!!
About ls
for icr
, would be nice to have:
ls String
: to show all methods defined in String
(but not in Comparable
/ Object
)ls -a String
(or similar, with a crystal syntax): to show all available methods in String
, including methods from included modules, base classes, etc.. (Comparable
/ Object
/ Reference
...)With full methods signature, and maybe a mention when the method is generated from a macro (not possible yet from macros, but maybe we can find a workaround)
Ruby's Pry gem has a nice
ls
method to list all object methods: https://github.com/pry/pry/wiki/State-navigation#learning-about-your-context-with-the-ls-command .It will be really helpful to have this feature in Icr.