[b]First of all, use SimpleDelegator class[/b]
1.first new a class
2.new another class extends SimpleDelegator,and donot forget require "delegate" at top of file
3.in this subclass ,super(obj) should be added in end of method initialize
4.let's look at code
and then output "hello world" string
1.first new a class
2.new another class extends SimpleDelegator,and donot forget require "delegate" at top of file
3.in this subclass ,super(obj) should be added in end of method initialize
4.let's look at code
require 'delegate'
class Hello
def helloworld()
"hello world"
end
end
class MyDelegate < SimpleDelegator
def initialize
@hello = Hello.new
super(@hello)
end
def setObj
__setobj__(@hello);
end
end
hello = MyDelegate.new
hello.setObj
puts hello.helloworld
and then output "hello world" string