From: Erik Veenstra Date: 2006-02-09T01:43:21+09:00 Subject: Re: Meta-Meta-Programming > def def_types(*types) > wrap_module_method(:method_added) do |org_method, args, block| > if types > method_name = args[0] > t = types > types = nil # Avoid looping > typed(method_name, *t) > end > > org_method.call(*args, &block) if org_method > end > end > > Since we do a "wrap_module_method" in "method_added" and > "wrap_module_method" does a "wrap_method" and "wrap_method" > adds a method and thus does a "method_added", the wrapped > "method_added" gets called over and over again. That's why I > introduced this loop-avoiding-system. You only have to add > this mechanism when wrapping Module#method_added, not for > other module methods. A bit more readable: "def_types" wraps "method_added." From now on, every time "method_added" is called, it calls "typed" (if we remove "if types"), which calls "wrap_method," which adds methods and thus triggers "method_added." And so on. This "types = nil", also applies the wrapping to *only* the next method (only to Foo#bar1 and not to Foo#bar2). gegroet, Erik V. - http://www.erikveen.dds.nl/