[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Issue extending a delegated class

dblack

7/27/2006 12:47:00 AM

3 Answers

rak rok

7/27/2006 4:24:00 AM

0

Hi David,

> > I would have expected b.one to output:
> > A::one
> > custom
>
> (Do you mean "foo" rather than "custom"?)

(Woops, yes i meant "foo")

> Your guess is right :-) When a handles the delegate call to #one,
> part of that call is a call to #two -- which, as far as a is
> concerned, is A#two.
>
> You can always override A#two, but I imagine that's not what you have
> in mind. I'm not sure exactly what you are trying to do, though.

Makes sense.. But then how is it possible to override A#two if all I
have is an instance of B?

Thanks!
-rak-

> David
>
> --
> http://www.rubypoweran... => Ruby/Rails training & consultancy
> http://www.manning... => RUBY FOR RAILS (reviewed on
> Slashdot, 7/12/2006!)
> http://dablog.r... => D[avid ]A[. ]B[lack's][ Web]log
> dblack@wobblini.net => me
>
>

dblack

7/27/2006 4:36:00 AM

0

rak rok

7/27/2006 4:44:00 AM

0

> You really want b's delegated object to have a new #two -- so:
>
> class << b.__getobj__
> def two
> puts "custom"
> end
> end

Awesome, I didn't know about __getobj__, thanks a lot.

-rak-

PS. Thanks for a great book!