Skip to content

Instantly share code, notes, and snippets.

@dohzya
Created August 1, 2009 08:14
Show Gist options
  • Save dohzya/159603 to your computer and use it in GitHub Desktop.
Save dohzya/159603 to your computer and use it in GitHub Desktop.
Example of namespace aware send implementation
class Object
# invoke the method meth of the module mod
def mod_send(mod, meth, *args, &bloc)
if self.is_a? mod
mod.instance_method(meth).bind(self).call(*args, &bloc)
else
method_missing("#{mod}::#{meth}", *args, &bloc)
end
end
end
if $0 == __FILE__
module M1
def foo
puts "#{M1}::#{self}"
end
end
module M2
def foo
puts "#{M2}::#{self}"
end
end
class C
include M1
include M2
end
C.new.mod_send M1, :foo
C.new.mod_send M2, :foo
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment