Introducing include_with_respect


Find out if your include/extend hooks are misbehaving!

Why did I make this gem?

Modules have hooks on include and extend, among others. These will run every time a module is included or extended into another module or class. If the hooks should only run once, (think shared state), then running them multiple times can cause difficult to trace bugs. This gem allows developers to trace modules that are re-included multiple times into other objects.

Total Downloads Downloads Today Network Stars Version Build Maintainability Test Coverage Depfu Open Source Helpers License: MIT


Add this line to your application’s Gemfile:

gem 'include_with_respect'

And then execute:

$ bundle

Or install it yourself as:

$ gem install include_with_respect


Example Use with ActiveSupport::Concern

module MyConcern
  extend ActiveSupport::Concern
  included do
    include IncludeWithRespect::ConcernWithRespect
    include SomeOtherConcern

Then if MyConcern is included somewhere that also includes SomeOtherConcern two things will happen that normally do not: 1. a warning will be printed (via puts) 2. the duplicate inclusion will be skipped (meaning the hooks will not run again) - This is a major change in the behavior of including modules, but normally hooks running multiple times is not desired, or intended, which is why this gem exists!


After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at

Create an issue and tell me about it, or fix it yo’sef.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
  6. Create new Pull Request


This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.

As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision.

For example:

spec.add_dependency 'include_with_respect', '~> 0.0'
More Reading
Older// CV
comments powered by Disqus