From: "R. Kumar" Date: 2010-02-02T00:10:09+09:00 Subject: Re: Inheritance related problem Rick Denatale wrote: > On Mon, Feb 1, 2010 at 1:54 AM, R. Kumar wrote: >>> I'm having trouble understanding how you got into this position. �I'm >> >> att=Ncurses::A_NORMAL >> � � �super(row - @top, col - @left, height, width, �color, att) >> � �end >> >> Now in the parent Window, print_border does a call to printstring to >> reset the background. Unfortunately, the child's printstring gets called >> and @top and @left get decremented again. > > So why not just factor out what's different between Parent and Child > > class Parent > def printstring(row, col, ... other parameters omitted) > row, col = *transform(row, col) > # do whatever you need > end > > def transform(row, col) > [row, col] > end > end > > class Child < Parent > def transform(row, col) > [row - @top, col - @left] > end > end > Aah, there are more such methods. SO in the second method print_border which happens to call printstring I would save row, col for the next call. > class Parent > def print_border(row, col, ... other parameters omitted) >- row, col = *transform(row, col) >+ nrow, ncol = *transform(row, col) > # do whatever you need with nrow and ncol >+ printstring row, col # using original args > end Looks good, will give it a try. I feel there's still something "off" in what i've done, and the question I am asking you, since it requires the parent to protect itself from (or know of) misbehaviour from a child. The overriding in Child was tacked on hastily and worked great till i noticed some cases where an extra line was getting erased. Thanks a lot. -- Posted via http://www.ruby-forum.com/.