Hi all, I have a problem in identifying whether a global method exist or not, from inside class, My code is similar to, ====================def myMethod "my Method is executed\n" end class MyClass def instMethod if(respond_to?("myMethod")) myMethod else p "myMethod not found\n" end end end me = MyClass.new me.instMethod ==================== Here "respond_to?("myMethod")" fails, It seems to be only checking the methods inside the class, not global methods. So I like to know is there anyway to do this? Thanks Dimuthu --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Nov-19 10:08 UTC
Re: Check Global method exist inside a class method
On 19 Nov 2007, at 09:20, Dimuthu wrote:> > > Here "respond_to?("myMethod")" fails, It seems to be only checking the > methods inside the class, not global methods. >top levels methods like that aren''t ''global'' methods, they end up as private methods on Object. Fred> So I like to know is there anyway to do this? > > Thanks > Dimuthu > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Frederick, Did you mean I should check with, Object.respond_to?("myMethod"). But It still it didnt'' work. Is that the Object you mention is not what I mean here? Can you please explain it little bit more? Thanks Dimuthu On Nov 19, 3:08 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 19 Nov 2007, at 09:20, Dimuthu wrote: > > > Here "respond_to?("myMethod")" fails, It seems to be only checking the > > methods inside the class, not global methods. > > top levels methods like that aren''t ''global'' methods, they end up as > private methods on Object. > > Fred > > > So I like to know is there anyway to do this? > > > Thanks > > Dimuthu--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Nov-19 15:00 UTC
Re: Check Global method exist inside a class method
On 19 Nov 2007, at 14:31, Dimuthu wrote:> > Hi Frederick, > > Did you mean I should check with, Object.respond_to?("myMethod"). But > It still it didnt'' work. Is that the Object you mention is not what I > mean here? > Can you please explain it little bit more?by default, respond_to doesn''t check for private methods, but you can force it : Object.respond_to?(:myMethod, true) Fred> > > Thanks > Dimuthu > > On Nov 19, 3:08 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 19 Nov 2007, at 09:20, Dimuthu wrote: >> >>> Here "respond_to?("myMethod")" fails, It seems to be only checking >>> the >>> methods inside the class, not global methods. >> >> top levels methods like that aren''t ''global'' methods, they end up as >> private methods on Object. >> >> Fred >> >>> So I like to know is there anyway to do this? >> >>> Thanks >>> Dimuthu > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, It works Dimuthu On Nov 19, 8:00 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 19 Nov 2007, at 14:31,Dimuthuwrote: > > > > > Hi Frederick, > > > Did you mean I should check with, Object.respond_to?("myMethod"). But > > It still it didnt'' work. Is that the Object you mention is not what I > > mean here? > > Can you please explain it little bit more? > > by default, respond_to doesn''t check for private methods, but you can > force it : Object.respond_to?(:myMethod, true) > > Fred > > > > > Thanks > >Dimuthu > > > On Nov 19, 3:08 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 19 Nov 2007, at 09:20,Dimuthuwrote: > > >>> Here "respond_to?("myMethod")" fails, It seems to be only checking > >>> the > >>> methods inside the class, not global methods. > > >> top levels methods like that aren''t ''global'' methods, they end up as > >> private methods on Object. > > >> Fred > > >>> So I like to know is there anyway to do this? > > >>> Thanks > >>>Dimuthu--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---