If we are calling an instance method on particular instance of an object as: @obj1.perform_sanity_check(@obj2) Will the instance method perform_sanity_check have access to @obj1 attributes? How do I / Do I need to pass this @obj1 to perform_sanity_check? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 15, 6:22 am, Amita Bhatkhande <rails-mailing-l...@andreas- s.net> wrote:> If we are calling an instance method on particular instance of an object > as: > @obj1.perform_sanity_check(@obj2) > > Will the instance method perform_sanity_check have access to @obj1 > attributes?Yes. Fred> > How do I / Do I need to > pass this @obj1 to perform_sanity_check? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Will the instance method perform_sanity_check have access to @obj1 > attributes?yes, with self.attribute --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
In object-oriented programming and your example, @obj1 is not being "passed" to perform_sanity_check, it is the "receiver object," the object being "asked" to execute its perform_sanity_check method. In a way, you are sending a message to the object @obj, requesting that it execute one of its methods. Does @obj1 have access to @obj1''s attributes? That depends on the context. If @obj1.perform_sanity_check appears in the implementation of one of @obj1''s instance methods, inside the @obj1''s class definition, then @obj1 can access the instance variables using self.instance_variable or @instance_variable. Otherwise, the instance variables aren''t directly accessible (Ruby encapsules object impelementation). They may be accessible through accessor methods, methods that may be defined in @obj1''s class definition provided to (indirectly) access them. See: "The Ruby Programming Language" by Flanagan & Matsumoto, Chapter 7: Classes and Modules. On Mar 14, 11:22 pm, Amita Bhatkhande <rails-mailing-l...@andreas- s.net> wrote:> If we are calling an instance method on particular instance of an object > as: > @obj1.perform_sanity_check(@obj2) > > Will the instance method perform_sanity_check have access to @obj1 > attributes? > > How do I / Do I need to > pass this @obj1 to perform_sanity_check? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
In object-oriented programming and your example, @obj1 is not being "passed" to perform_sanity_check, it is the "receiver object," the object being "asked" to execute its perform_sanity_check method. In a way, you are sending a message to the object @obj, requesting that it execute one of its methods. Does @obj1 have access to @obj1''s attributes? That depends on the context. If @obj1.perform_sanity_check appears in the implementation of one of @obj1''s instance methods, inside the @obj1''s class definition, then @obj1 can access the instance variables using self.instance_variable or @instance_variable. Otherwise, the instance variables aren''t directly accessible (Ruby encapsules object impelementation). They may be accessible through accessor methods, methods that may be defined in @obj1''s class definition provided to (indirectly) access them. See: "The Ruby Programming Language" by Flanagan & Matsumoto, Chapter 7: Classes and Modules. On Mar 14, 11:22 pm, Amita Bhatkhande <rails-mailing-l...@andreas- s.net> wrote:> If we are calling an instance method on particular instance of an object > as: > @obj1.perform_sanity_check(@obj2) > > Will the instance method perform_sanity_check have access to @obj1 > attributes? > > How do I / Do I need to > pass this @obj1 to perform_sanity_check? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---