protected_instance_methods is a Module method for inspecting protected instance methods on a class or module. Unlike obj.protected_methods, which examines a regular object's available methods, it queries the instance-method definitions associated with the class or module itself. section 7.7.3 section 15.2.3
Choose the scope of the method list with an optional argument:
- protected_instance_methods returns protected instance methods from the receiver and, by default, its ancestor classes and modules. section 15.2.3
- protected_instance_methods(false) restricts the result to methods defined directly by the queried class or module. section 15.2.3
- Related queries include instance_methods for public and protected methods, public_instance_methods for public methods, and private_instance_methods for private methods. section 15.2.3
- Keeping the receiver and requested scope clear prevents confusion between a class or module query and an object-level query. section 7.7.3
Inspecting only a class's protected definitions
Use the same receiver-and-scope pattern shown by other class-level queries: Range.protected_instance_methods(false) asks for protected instance methods defined by Range itself, while Range.protected_instance_methods also includes definitions supplied by ancestors and included modules. The false form is useful when narrowing a method list to the class's own definitions. section 15.2.3 section 7.7.3
>> Range.instance_methods(false).sort
=> [:%, :==, :===, :begin, :bsearch, :count, :cover?, :each, :end,
:entries, :eql?, :exclude_end?, :first, :hash, :include?, :inspect,
:last, :max, :member?, :min, :minmax, :overlap?, :pretty_print,
:reverse_each, :size, :step, :to_a, :to_s]
Compare Range.instance_methods(false) with the corresponding protected-instance query to see how the false argument narrows inspection to definitions made directly by the receiver. section 15.2.3
