How to search for methods on a massive Ruby object

While debugging Autovist today, I wanted to see what methods the Tweet object supported (from the Twitter gem, which wraps the Twitter API) in order to figure out why the message was null.  As you can see below, it doesn’t have a nice way of dumping out all values for inspection.  🙁

So I used

(byebug) tweet.methods

to introspect and got MUCH more than I bargained for:

Whoa! That’s a lot of methods. How many are there?

(byebug) tweet.methods.size
178

That’s just too many to read through.  So lets discover all methods related to YAML:

(byebug) tweet.methods.select{|e| /yaml/ === e}
[:psych_to_yaml, :to_yaml, :to_yaml_properties]

So much better!

What I really want to discover is if the Twitter gem version I’m using supports information about quoted tweets.  I suspect it does not because I’m using 5.14 and the github diff shows 5.15:

So lets check:

(byebug) tweet.methods.select{|e| /quote/ === e}
[]

Nope!  I’ll need to upgrade my gem version if Autovist is going to work with quoted tweets.

Well – that’s it.  Another reason we love Ruby so much.  Its a beautiful language, easy to start using, but so incredibly powerful, deep and rich that I could spend the rest of my life exploring and mastering it.

Chris Downey

Founder, VaxCalc Labs and creator of Autovist and the Vaccine Ingredients Calculator.

Author: Chris Downey

Founder, VaxCalc Labs and creator of Autovist and the Vaccine Ingredients Calculator.

Leave a Reply