Created
July 9, 2009 08:40
-
-
Save saivenkat/143516 to your computer and use it in GitHub Desktop.
Include or Extend module dynamically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Base | |
| def call | |
| "I am called" | |
| end | |
| end | |
| class Child | |
| def help | |
| "Please help me" | |
| end | |
| end | |
| # To include the Base dynamically to Child | |
| child1 = Child.send(:include, Base) | |
| child1.new.call #=> I am called | |
| # To extend the Base dynamically to Child | |
| child2 - Child.send(:extend, Base) | |
| child2.call #=> I am called |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment