hei
2008-Mar-18 05:47 UTC
Can an object obj-arbitrary respond to a method with arbitary name?
For example: I create an object c. Now, if I call c.xxx, ruby just raise an exception ''method missing'' But, I want it return nil, for each method which is not pre-defined. Is there a way I can gain this ? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dhaval
2008-Mar-18 06:04 UTC
Re: Can an object obj-arbitrary respond to a method with arbitary name?
If you are doing something like this s = c.xxx then u can always give recue nil which would then set the value of s as nil. On Mar 18, 10:47 am, hei <cy...-KN7UnAbNpbg@public.gmane.org> wrote:> For example: > I create an object c. > Now, if I call c.xxx, ruby just raise an exception ''method missing'' > But, I want it return nil, for each method which is not pre-defined. > Is there a way I can gain this ? > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hei
2008-Mar-18 06:32 UTC
Re: Can an object obj-arbitrary respond to a method with arbitary name?
Thank you!~ I imaged there may be some trigger, open it, then object of some class will response to every method. close it, then exception raises. I wanna the classes predefined by ruby/rails can have this functionality. Can anyone tell me how to diy it ? For example, I want a model class has this kind of trigger. On Mar 18, 2:04 pm, dhaval <dhaval.deshpan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If you are doing something like this s = c.xxx then u can always give > recue nil which would then set the value of s as nil. > > On Mar 18, 10:47 am, hei <cy...-KN7UnAbNpbg@public.gmane.org> wrote: > > > > > For example: > > I create an object c. > > Now, if I call c.xxx, ruby just raise an exception ''method missing'' > > But, I want it return nil, for each method which is not pre-defined. > > Is there a way I can gain this ? > > Thanks!- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dhaval
2008-Mar-18 07:48 UTC
Re: Can an object obj-arbitrary respond to a method with arbitary name?
Then I think yo need to write your custom method_missing in you model class. This is how rails actually creates its dynamic finders by invoking method_missing in base.rb. Or you can actually modify the method_missing in base.rb as per your need. On Mar 18, 11:32 am, hei <cy...-KN7UnAbNpbg@public.gmane.org> wrote:> Thank you!~ > I imaged there may be some trigger, open it, then object of some class > will response to every method. close it, then exception raises. > I wanna the classes predefined by ruby/rails can have this > functionality. > Can anyone tell me how to diy it ? > For example, I want a model class has this kind of trigger. > > On Mar 18, 2:04 pm, dhaval <dhaval.deshpan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > If you are doing something like this s = c.xxx then u can always give > > recue nil which would then set the value of s as nil. > > > On Mar 18, 10:47 am, hei <cy...-KN7UnAbNpbg@public.gmane.org> wrote: > > > > For example: > > > I create an object c. > > > Now, if I call c.xxx, ruby just raise an exception ''method missing'' > > > But, I want it return nil, for each method which is not pre-defined. > > > Is there a way I can gain this ? > > > Thanks!- Hide quoted text - > > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hei
2008-Mar-18 08:57 UTC
Re: Can an object obj-arbitrary respond to a method with arbitary name?
Thank very much! That''s just I want. I lack of knowledge about how rails works, I think. Thanks a lot!! On Mar 18, 3:48 pm, dhaval <dhaval.deshpan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Then I think yo need to write your custom method_missing in you model > class. This is how rails actually creates its dynamic finders by > invoking method_missing in base.rb. Or you can actually modify the > method_missing in base.rb as per your need. > > On Mar 18, 11:32 am, hei <cy...-KN7UnAbNpbg@public.gmane.org> wrote: > > > > > Thank you!~ > > I imaged there may be some trigger, open it, then object of some class > > will response to every method. close it, then exception raises. > > I wanna the classes predefined by ruby/rails can have this > > functionality. > > Can anyone tell me how to diy it ? > > For example, I want a model class has this kind of trigger. > > > On Mar 18, 2:04 pm, dhaval <dhaval.deshpan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > If you are doing something like this s = c.xxx then u can always give > > > recue nil which would then set the value of s as nil. > > > > On Mar 18, 10:47 am, hei <cy...-KN7UnAbNpbg@public.gmane.org> wrote: > > > > > For example: > > > > I create an object c. > > > > Now, if I call c.xxx, ruby just raise an exception ''method missing'' > > > > But, I want it return nil, for each method which is not pre-defined. > > > > Is there a way I can gain this ? > > > > Thanks!- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---