Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created February 18, 2009 07:46
Show Gist options
  • Save jugyo/66249 to your computer and use it in GitHub Desktop.
Save jugyo/66249 to your computer and use it in GitHub Desktop.
module Delegatable
def delegate(from_obj, from_method, to_obj, to_method)
from_obj.extend Module.new{
define_method(from_method) do |*arg|
to_obj.__send__(to_method, *arg)
end
}
end
end
class Test2
def test
puts self.class.to_s
end
end
class Test1
extend Delegatable
@@t2 = Test2.new
delegate self, :_test, @@t2, :test
end
Test1._test
o = Object.new
extend Delegatable
delegate o, :_hoge, Test1, :_test
o._hoge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment