< up >

ruby - get plain class/instance method list

tl;dr: <your-class>.methods - Object.methods

Whenever I juggle with ruby classes or instances within a ruby REPL1, I had hard times to figure out their methods:

> Time.methods
=> [:at,

I was today years old when I leaned about just subtracting the Object methods (from ruby’s holy base object) from SO:

pry(main)> Time.methods - Object.methods
=> [:at, :now, :utc, :gm, :local, :mktime]

As of writing this post, I just noticed that the relevant class/instance methods are at the beginning of the list, which is kind of handy, too.

  1. pry ftw.