Just to be clear I meant to say why not just factor out JUST what's differe=
nt.

On Mon, Feb 1, 2010 at 8:59 AM, Rick DeNatale <rick.denatale / gmail.com> wro=
te:
> On Mon, Feb 1, 2010 at 1:54 AM, R. Kumar <sentinel.2001 / gmx.com> wrote:
>> Sean DeNigris wrote:
>>>> When Parent's printa is called, it calls its own printb.
>>>> However, when Child's printa is called, it calls Parent's printa, whic=
h
>>>> (in this case) i was hoping would call Parent's printb directly. But i=
t
>>>> (correctly) calls Child's printa which once again reduces the arg.
>>>>
>>>> So my arg gets reduced twice. I suppose i could use some flags to
>>>> prevent this, But is there any direct way i can coerce Parent printa t=
o
>>>> call only Parent printb.
>>>
>>> I'm having trouble understanding how you got into this position. =A0I'm
>>> assuming that you don't own Parent, and so have to work your magic in
>>> Child. =A0For the specific example you described, the following will
>>> work...
>>>
>>
>> I own both. Parent is a wrapper around ncurses Window. Child is a
>> wrapper around ncurses Pad. However, they are used in a similar manner.
>> So in the original app, i used only Window. Now in many cases I use Pad.
>> They both should work interchangeably since they essentially do the same
>> thing but often in different ways. An object could use Window, or Pad.
>>
>> However, stuff like printing a border or writing a string onto the
>> window are essentially the same except that the offsets in Window are
>> absolute whereas the Pad offsets are relative. So when Pad calls super
>> it only has to make the relative offsets absolute:
>>
>> =A0 =A0def printstring(row, col, value, color, attrib=3DNcurses::A_NORMA=
L)
>> =A0 =A0 =A0super(row - @top, col - @left, value, color, attrib)
>> =A0 =A0end # printstring
>>
>> =A0 =A0def print_border row, col, height, width, color,
>> att=3DNcurses::A_NORMAL
>> =A0 =A0 =A0super(row - @top, col - @left, height, width, =A0color, att)
>> =A0 =A0end
>>
>> 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
> =A0def printstring(row, col, ... other parameters omitted)
> =A0 =A0 =A0row, col =3D *transform(row, col)
> =A0 =A0 =A0# do whatever you need
> =A0end
>
> =A0def transform(row, col)
> =A0 =A0 [row, col]
> =A0end
> end
>
> class Child < Parent
> =A0 def transform(row, col)
> =A0 =A0 =A0 [row - @top, col - @left]
> =A0 end
> end
>
> --
> Rick DeNatale
>
> Blog: http://talklikeaduck.denhaven2.com/
> Twitter: http://twitter.com/RickDeNatale
> WWR: http://www.workingwithrails.com/person/9021-rick-denatale
> LinkedIn: http://www.linkedin.com/in/rickdenatale
>
>



--=20
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale