From: Tom Sawyer Date: 2002-07-24T00:52:46+09:00 Subject: Re: define_method with super in the proc On Tue, 2002-07-23 at 09:32, David Alan Black wrote: > I'm losing sight of the goal here. What's the advantage of this kind > of indirectness and extra work, when you can just write the code? > > class B < A > def doit > super > @y = 10 > end > end > > Normally I would assume that a small example is encapsulating > something that one would want to do one a larger scale, but I'm not > sure what that would be here. (By "here" I mean the question raised > in the whole thread, not just this example.) well here's my code (slight out of date now). you'll notice i have super remarked out, and i'm just redefining the the method. but like i said i don't know how this works exactly in some cases, i.e. when the method is an assignment (#x=). (i didn't include any of the widget classes this draws upon, but you can imagine) # Widget Factory # Returns a new widget object of specialized widget class def WidgetFactory.new(widget, bindings={}, attributes={}) # a string name will work too widget = widget.intern if widget.is_a?(String) # makes an anoynomous class as subclass of desired widget widgetClass = Class.new(WidgetFactory.const_get(widget)) # specialize class via bindings bindings.each do |k, v| widgetClass.class_eval { define_method(k) { |*args| #super v[0].send(v[1], *args) } } end return widgetClass.new(attributes) end so you see i'm sort of dynamically creating classes. does that help? -- ~transami