Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: implement ls keyword to list all object methods (like in Pry) #103

Open
vifreefly opened this issue Jan 2, 2019 · 3 comments
Open

Comments

@vifreefly
Copy link

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.

@greyblake
Copy link
Member

greyblake commented Jan 6, 2019

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.

@bew
Copy link

bew commented Jan 6, 2019

@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 :)

@greyblake greyblake reopened this Jan 6, 2019
@bew
Copy link

bew commented Feb 6, 2019

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants