From: matz@... (Yukihiro Matsumoto) Date: 2000-09-13T00:46:14+09:00 Subject: [ruby-talk:4899] Re: Re-binding a block Hi, In message "[ruby-talk:4895] Re: Re-binding a block" on 00/09/12, Dave Thomas writes: |I'm trying to do something more generic, and that also avoids the |problems with infinite loops that can arise with renaming in |subclasses. How about this? Although it's bit ugly. $hook_table = {} class Module def hook(name, block) n = format("%s#%s", self.name, name) $hook_table[n] = instance_method(name) module_eval %{ def #{name}(*args) m = $hook_table["#{n}"] lambda{#{block}}.call(m.bind(self), *args) end } end end class String hook :upcase, %{|upcase, *rest| upcase.call(*rest).tr '_', '~' } end p "foo_".upcase matz.