Ruby equivalent of Python's “dir”?

后端 未结 9 1641
温柔的废话
温柔的废话 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:45

    If I stricly read your question, I must answer it that way: a file as specified by require in Ruby is just a container and does not have necessarely have any relation with a class. The content can be:

    • a class
    • a module
    • plain code

    or any combination of the above, several times. So you can not directly ask for all methods in a given file.

    If you meant to list all methods of a given module or class, then the other answers are what you seek (mainly using the #methods method on a module name or class).

提交回复
热议问题