Skip to content

Instantly share code, notes, and snippets.

@saivenkat
Created July 9, 2009 08:40
Show Gist options
  • Select an option

  • Save saivenkat/143516 to your computer and use it in GitHub Desktop.

Select an option

Save saivenkat/143516 to your computer and use it in GitHub Desktop.
Include or Extend module dynamically
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