2.3. The innate behaviors of an object
Even a newly created object isn’t a blank slate. As soon as an object comes into existence, it responds to a number of messages. Every object is “born” with certain innate abilities.
To see a list of innate methods, you can call the methods method (and throw in a sort operation, to make it easier to browse visually):
p Object.new.methods.sort
The result is a list of all the messages (methods) this newly minted object comes bundled with. (Warning: The output looks cluttered. This is how Ruby displays arrays—and the methods method gives you an array of method names. If you want a list of the methods one per line, use puts instead of p in the command.)
[:!, :!=, :!~, :<=>, :==, :===, :=~, :__id__, :__send__, ...
Get The Well-Grounded Rubyist, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.