Ruby equivalent of Python's “dir”?

后端 未结 9 1632
温柔的废话
温柔的废话 2020-12-23 16:09

In Python we can \"dir\" a module, like this:

>>> import re
>>> dir(re)

And it lists all functions in the module. Is ther

9条回答
  •  庸人自扰
    2020-12-23 16:44

    Maybe not answering the original question (depends on the use case), but for those who are looking for this to be used in the irb only, you can use "double-TAB" for autocompletion. Which, effectively, can also list (almost all) the methods available for a given object.

    Put the following line into your ~/.irbrc file:

    require 'irb/completion'
    

    Now, (re)start the irb, start typing a method and hit TAB twice - irb autocompletes the input!

    I actually learned it here: http://drnicwilliams.com/2006/10/12/my-irbrc-for-consoleirb/

提交回复
热议问题