Skip to content

Instantly share code, notes, and snippets.

@banister
Created November 2, 2010 12:47
Show Gist options
  • Save banister/659561 to your computer and use it in GitHub Desktop.
Save banister/659561 to your computer and use it in GitHub Desktop.
exploiting the fact that a method aliasing itself adds the method onto the m_tbl of the receiver
# Traits in Ruby:
module M
def self.included(c)
c.class_eval do
instance_methods.each do |m|
alias_method m, m
end
end
c.uninclude(self)
end
def hello
:hello
end
end
class C
include M
end
# hello method injected directly into m_tbl of C
C.ancestors #=> [C, Object, ...] # Module not included
C.new.hello #=> hello # Yet method still accessible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment