青山です。

Sat, Feb 13, 1999 at 12:37:36AM +0900 において
松尾尚典 さん曰く:

> class B < Hash
>   def help
>     print "help\n"
>   end
> end
> 
> test = B.new
> test['a'] = 'b'
> p test     # {'a'=>'b'}
> test.help  # "help\n" を出力
> 
> 継承は当然使わずに、っていう前提なのかしら。

あ、いえ、Hash ではいまいちでしたね。String にしてみましょうか。

class S < String
  def initialize
    self = "a"        # 不可
    self.concat("a")  # 不可
  end
end

という事で、

require "delegate"
class S < SimpleDelegator
  def initialize
    @string = "a"
    super(@string)
  end
end
p S.new # "a"

という感じです。(実は help の追加の方がおまけだったんですね)


-- 
青山 和光 Wakou Aoyama <wakou / fsinet.or.jp>