Ruby’s methods method returns an array of symbols naming the methods an object can call. Sorting the result makes a large capability list easier to browse. section 2.3 section 15.2.1
A methods query includes:
- Methods inherited through the object’s ancestry. section 7.7.1
- Methods supplied by included modules, even when inclusion happens after an object exists. section 7.7.1
- Singleton methods defined specifically for that object. section 7.7.1
- For class and module objects, methods callable on the class or module itself—not methods available to their instances. section 7.7.1
Filtering a capability list
Given string = "Test string", string.methods.grep(/case/).sort finds case-related names such as :downcase, :swapcase, and :upcase. The returned symbols can be filtered, sorted, and compared to answer questions about an object’s capabilities. section 15.2.1 section 15.2
>> "I am a String object".methods.sort
Inspecting and sorting a real String object’s method names makes the returned array and its scale visible. section 7.7.1
