liveBook · Manning

Public_instance_methods

As explained in The Well-Grounded Rubyist, Fourth Edition

public_instance_methods is a Ruby Module method that returns the public instance methods available from a class or module, optionally including inherited and included methods.

public_instance_methods is a class- or module-level query that returns the public instance methods available to instances. It is a synonym for instance_methods when selecting public methods, rather than protected ones. section 7.7.3 section 15.2.3

Own methods versus inherited methods

Range.public_instance_methods(false) restricts the result to public methods defined directly by Range. Calling Range.public_instance_methods without an argument also includes public methods supplied by ancestor classes and modules. section 15.2.3

Use the method-listing family to inspect different parts of a class or module's instance-method surface:

  • instance_methods returns public and protected instance methods. section 15.2.3
  • public_instance_methods returns only public instance methods; protected_instance_methods and private_instance_methods select the other visibility levels. section 15.2.3
  • Intersect method lists with & to identify methods shared by a class and a module, such as Range and Enumerable. section 15.2.3
String.instance_methods(false).sort

Inspect String's directly defined instance methods and sort the resulting list for a fine-grained view of method placement. section 7.7.3

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Explains visibility, ancestor inclusion, and false-based filtering, then stops short of method implementation details.
Examples
Uses String and Range listings, plus Enumerable intersections, to demonstrate direct definitions and overridden methods.
What it assumes
Assumes familiarity with classes, modules, instance methods, visibility, and inheritance; distinguishes class-level from regular-object queries.
What you can do after
Diagnose/debug with it by locating public methods defined directly by a class or contributed through its ancestors and modules.
How it connects
Connects Module introspection with instance_methods, protected_instance_methods, private_instance_methods, ancestor classes, and modules.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.