I'm coming to Ruby from Python, and I'm wondering if Ruby has some equivalent of dir()
in Python that I can use within the IRB. I was looking at this SO thread linked below, where it appears to not be the case, but it's a 6 year old post so I was trying to find out if anything had changed since then.
Ruby Equivalent of Python dir?
objects.methods.sort
is nice, but I want to see things like instance/class variables on an object as well (really everything publicly available in the namespace), not just methods.
Ruby can tell you the methods: obj.methods
.
There's also: #public_methods, #instance_methods, #private_methods, etc.
Ruby can tell you the instance variables #instance_variables
. Ruby can't tell you the documentation; there's no docstring like there is in Python. There are some enhancements to irb available that give an ri command from within irb.
有一种非常流行的gem pry ,它具有称为ls
方法,可以为您提供一些我相信的东西,类似于Python中的dir
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.