Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

module-mixins

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

module-mixins

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Module::Mixins

Gem Version Build Status Dependency Status Code Climate

Help with inspecting mixed-in Ruby modules.

Install

Add module-mixins to your Gemfile.

gem 'module-mixins'

Use

Find All Classes that Include a Module

In order to find all classes that include a module you would typically track those via the Module.included callback.

module MyModule
  attr_accessor :classes_including

  def included(base)
    self.classes_including ||= []
    self.classes_including << base
  end
end

This works well and is the behavior implemented in module-mixins by Module::Mixins::Included. You can extend your modules instead of duplicating code.

module MyModule
  extend Module::Mixins::Included
end

Ruby also provides a mechanism to enumerate all constants, which enables us to find mixed-in modules dynamically.

You can extend a module and call classes_including similarly.

module MyModule
  extend Module::Mixins::Including
end

You can also extend existing modules, which is quite powerful because you can apply it to modules you have not declared in your own code.

irb> Enumerable.extend Module::Mixins::Including
 => Enumerable

irb> Enumerable.classes_including
 => [Array, Hash, Struct, ..., Set, SortedSet]

You can also use a module method without needing to mix-in another module.

irb> Module::Mixins::Including.classes_including(Comparable)
 => [String, Symbol, Numeric, ..., Date, DateTime]

References

Contribute

See CONTRIBUTING.

Copyright Daniel Doubrovkine and Contributors, Artsy Inc., 2015

MIT License

FAQs

Package last updated on 04 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc