1

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.

Community
  • 1
  • 1
blindsnowmobile
  • 3,868
  • 6
  • 32
  • 47

2 Answers2

3

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.

MyGGaN
  • 1,766
  • 3
  • 30
  • 41
Ravi Rathore
  • 101
  • 1
  • 11
1

There is fairly popular gem pry, which has method called ls that can provide you I believe with something, similar to the dir in Python.

adamliesko
  • 1,887
  • 1
  • 14
  • 21