Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 756 Bytes

check-if-an-object-includes-a-module.md

File metadata and controls

25 lines (20 loc) · 756 Bytes

Check If An Object Includes A Module

You may want to know if an object's class includes a module because that will tell you something about the object's behavior. It is another way of asking if an object responds to a method or set of methods, assuming you know what methods the module provides.

This can be done with the Module#include? method.

# assuming some object book of type Book that includes Rateable
> book.class
=> Book
> book.class.include?(Rateable)
=> true

# assuming some object author of type Author that doesn't include Rateable
> author.class
=> Author
> author.class.include?(Rateable)
=> false

source