From: elbows@... (Nathan Weston) Date: 2003-12-06T04:12:03+09:00 Subject: Re: Using Modules as Decorators nobu.nokada@softhome.net wrote in message news:<200312040501.hB451XUm013568@sharui.nakada.kanuma.tochigi.jp>... > Hi, > > At Thu, 4 Dec 2003 07:17:07 +0900, > Nathan Weston wrote: > > def decorate(obj, name) > > #We have to eval string to avoid scope issues: > > #class << obj > > # alias_method(:orig_name(name), :name) <-- These variables > > # are substituted through string expansion > > #end > > eval("class << obj\nalias_method(:#{orig_name(name)}, :#{name})\nend") > > end > def decorate(obj, name) > orig = orig_name(name) > (class << obj; self; end).class_eval {alias_method(orig, name)} > end Cool! I was wondering if there was a syntax for that, but I couldn't figure it out so I just gave up and used eval. > > > #Call the original definition of name on object > > def call_orig(obj, name, *args) > > obj.send(orig_name(name), *args) > > end > def call_orig(obj, name, *args, &block) > obj.__send__(orig_name(name), *args, &block) > end What does __send__ do? And what's the block for? Nathan