In Ruby, including a Car module makes it a car!

Consider the following:

module Car
  def drive
    puts "brrrrr"
  end
end

module Train
  def drive
    puts "cho-choo!"
  end
end

class TeaCup
  include Car
end

tea = TeaCup.new

We have a Car and Train module, but we only include the Car in the TeaCup.

Accordingly I would expect a TeaCup to still be a TeaCup - but if we adopt the behaviour of a Car, should a TeaCup also be a Car?

Test yourself: what would you expect?

puts "tea.is_a? TeaCup: #{tea.is_a? TeaCup}"
puts "tea.is_a? Train: #{tea.is_a? Train}"
puts "tea.is_a? Car: #{tea.is_a? Car}"

The answers would surprise you:

# => tea.is_a? TeaCup: true
# => tea.is_a? Car: true
# => tea.is_a? Train: false

But why and how?

Straight from the documentation:

Returns true if class is the class of obj, or if class is one of the superclasses of obj or modules included in obj.

Ancestor Chains

For more information, please search online.

Written on March 4, 2026