From: Tom Sawyer Date: 2002-07-23T22:00:12+09:00 Subject: Re: define_method with super in the proc thanks kent, well, i'm going to upgrade and try out this alias bit. i was surprised to find my program working (under a simple test) even without the use of #super, but it may because it was using the class and not the instance. i'm a bit confused. so let me go into a little more detail and see what pointers you(s) can give me. basically, i have a class with an attribute like so: class A attr_accessor :a end then i subclass it: B = Class.new(A) i'm not sure if B should be capitalized, perhaps just b? anyway, then i override #a= in B. B.class_eval { define_method(:a=, Proc.new { super; puts a }) so the idea for B is to have #a= still set a, but also to print a. what's the best approach to solving this? it looks like i have to upgrade for starters. then try aliasing. i'll try that. does anyone have any other notions for accomplishing this? looks like building classes on the fly ain't as smooth as the rest of ruby. but then again, at least you can do it at all. like i said, right now my program dosen't have the #super and yet it seems to work. how does that make any sense? ~transami On Tue, 2002-07-23 at 06:06, Kent Dahl wrote: > ts wrote: > > Tue Oct 16 23:29:26 2001 Yukihiro Matsumoto > > > > * eval.c (rb_call0): self in a block given to define_method now be > > switched to the receiver of the method. > > Thank you. Since this is on the main branch, I take it the best bet > would be to compile from CVS and stay on the 1.7.* branch, if we want to > use define_method. > > However, after compiling it up (ruby 1.7.2 (2002-07-13) [i686-linux]), > I notice that this doesn't solve the super problem Tom had. (Which > probably means I probably was of on a big goose chase.) > > Anyway, back to the original problem. Tom, you could alias the super > method and pass its aliased name into the makeproc and call it > explicitly: > > class A > attr_reader :x, :y > def doit > @x = 5 > end > end > > def makeproc( supername ) > Proc.new { > self.send(supername) > @y = 10 > } > end > > B = Class.new(A) > B.class_eval { > alias doit_super_A doit > define_method(:doit, makeproc(:doit_super_A) ) > } > b = B.new > b.doit > p b #=> # > > > HTH, and sorry for depressing you in my previous post :-) > > -- > (\[ Kent Dahl ]/)_ _~_ __[ http://www.stud.ntnu.no/~kentda/ ]___/~ > ))\_student_/(( \__d L b__/ NTNU - graduate engineering - 4. year ) > ( \__\_�|�_/__/ ) _)Industrial economics and technological management( > \____/_�_\____/ (____engineering.discipline_=_Computer::Technology___) > -- ~transami