I'm just curious to know what exactly is the difference between methodsand public_methodsin Ruby? From RubyMonk Analysis section
The method of methods of the object allows us to go to the list available for the object and its ancestors. This is equivalent to using public_methods. They return the entire instance of the methods and methods of the class belonging to this object, and the methods available for this ancestor. If you want to ignore the ancestors and restrict the listing to only the recipient, you can pass in false for public_methods (false).
For curiosity, I also call methods(false)that return another conclusion from
public_methods(false)
My sample code and output:
p String.methods.size
p String.public_methods.size
p String.methods(false).size
p String.public_methods(false).size
p String.public_methods(false) - String.methods(false)
STDOUT:
235
235
3
19
[:json_create, :yaml_tag, :const_missing, :allocate, :new, :superclass, :cattr_reader, :cattr_writer, :cattr_accessor, :class_attribute, :superclass_delegating_accessor, :descendants, :subclasses, :duplicable?, :json_creatable?, :to_yaml]
, methods public_methods , , .