[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

1.8.x public send?

Trans

9/22/2008 5:41:00 PM

Oh crud,

class A
def initialize
@b = B.new
end
def method_missing(s, *a, &b)
@b.__send__(s,*a,&b)
end
end

class B
def method_missing(s,*a,&b)
"HERE"
end
end

A.new.foo

How to get "HERE"?

2 Answers

Michael Guterl

9/22/2008 7:03:00 PM

0

On Mon, Sep 22, 2008 at 1:40 PM, Trans <transfire@gmail.com> wrote:
> Oh crud,
>
> class A
> def initialize
> @b = B.new
> end
> def method_missing(s, *a, &b)
> @b.__send__(s,*a,&b)
> end
> end
>
> class B
> def method_missing(s,*a,&b)
> "HERE"
> end
> end
>
> A.new.foo
>
> How to get "HERE"?
>
>
Works for me.

I just had to `puts A.new.foo`

Trans

9/22/2008 7:41:00 PM

0



On Sep 22, 3:03=A0pm, "Michael Guterl" <mgut...@gmail.com> wrote:
> On Mon, Sep 22, 2008 at 1:40 PM, Trans <transf...@gmail.com> wrote:
> > Oh crud,
>
> > =A0class A
> > =A0 =A0def initialize
> > =A0 =A0 =A0@b =3D B.new
> > =A0 =A0end
> > =A0 =A0def method_missing(s, *a, &b)
> > =A0 =A0 =A0@b.__send__(s,*a,&b)
> > =A0 =A0end
> > =A0end
>
> > =A0class B
> > =A0 =A0def method_missing(s,*a,&b)
> > =A0 =A0 =A0"HERE"
> > =A0 =A0end
> > =A0end
>
> > =A0A.new.foo
>
> > How to get "HERE"?
>
> Works for me.
>
> I just had to `puts A.new.foo`

My bad, I mistook my trouble for this issue. But actually the trouble
only arises when:

class B
def method_missing(s,*a,&b)
"HERE"
end
private
def foo; 'foo'; end
end

Because method_missing applies to public calls and ignores private
ones.

T.