---
title: "Discussion on \"Ruby Hooks: Extending Class Functionality with the included Hook\" | Hashnode"
description: "Discussion on \"Ruby Hooks: Extending Class Functionality with the included Hook\". Introduction\nIn the world of Ruby programming, we often rely heavily on Rails due to its abundant support and convenient features. Rails concerns are commonly used in models or controllers to abstract"
url: "https://hashnode.com/posts/ruby-hooks-extending-class-functionality-with-the-included-hook/6ad25facd1cdce11c6be11b6"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Ruby Hooks: Extending Class Functionality with the included Hook](https://clearyourdoubt.in/ruby-hooks-extending-class-functionality-with-the-included-hook?utm_source=hashnode&utm_medium=feed)

Introduction In the world of Ruby programming, we often rely heavily on Rails due to its abundant support and convenient features. Rails concerns are commonly used in models or controllers to abstract

Oct 16 · 5 min read · clearyourdoubt.in  
Read the article

## Written by

[Atish Maske](https://hashnode.com/@atish23)

@atish23

  
[View profile](https://hashnode.com/@atish23)

## Responses 1

Markdown supported · ⌘↵ to post

[StackShortlist](https://hashnode.com/@veristria)

[Oct 17](https://hashnode.com/posts/ruby-hooks-extending-class-functionality-with-the-included-hook/6ad25facd1cdce11c6be11b6/comment/6ad335f4c0f95b323bff83b5)

The included plus base.extend(ClassMethods) pattern is clear. One thing to check in the InstanceCounter example: Person and Animal define their own initialize in the class body, and a method defined on the class wins over one from an included module. So InstanceMethods#initialize never runs and the counts stay at 0. Using base.prepend(InstanceMethods) puts the module in front of the class in the ancestor chain, so its initialize runs first and super reaches the class's version. Easy to confirm with Person.ancestors.
