What is the difference between a Class and a Module? When would you choose one over the other?

Last updated 27 June 2026

A class is a blueprint for objects that can be instantiated and inherited; a module is a bundle of methods/constants that cannot be instantiated but can be mixed into classes or used as a namespace. Use a class for "is-a" entities and a module to share behavior or organize names.

  • Class:

    • Can be instantiated with .new and supports single inheritance via <.

    • Models a thing with identity and state (a User, an Order).

  • Module:

    • Cannot be instantiated and has no inheritance.

    • Two jobs: a namespace (Math::PI) and a mixin of shared behavior via include or extend.

  • Choosing:

    • Need objects with state and an "is-a" relationship: class.

    • Need to share capabilities across unrelated classes ("has-a" / "can-do"): module mixin.

    • Ruby has single inheritance, so mixins are how it gets multiple-inheritance-like reuse.

  • https://www.turing.com/interview-questions/ruby
  • https://www.youtube.com/watch?v=lkunzd5uDrw
  • https://blog.jacobvosmaer.nl/0004-ruby-scheduler-interaction/
  • https://wohotech.in/coding/top-java-interview-questions
  • https://jetthoughts.com/blog/ruby-3-4-yjit-performance-guide/
  • https://speed.ruby-lang.org/
  • https://flexiple.com/python/interview-questions
  • https://www.it-jobs-nl.com/ruby-developer/
  • https://www.bacancytechnology.com/blog/outsource-ruby-on-rails-development
  • https://blog.nextideatech.com/how-to-hire-the-best-ruby-on-rails-developers-the-complete-guide/
  • https://ubiminds.com/en-us/ruby-on-rails-developers/
  • https://dataford.io/interview-guides/pattern/software-engineer
All Ruby interview questions