Created
February 18, 2009 07:46
-
-
Save jugyo/66249 to your computer and use it in GitHub Desktop.
This file contains 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 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