--0015174c4278f9c45004a36e1890 Content-Type: text/plain; charset=ISO-8859-1 Thank you all. Here I have another similar question: puts self main def hello; @v ; end il then I assume @v should be an instance variable of 'main', but puts self.instance_variables il Can anyone help explain? Many thanks! Brian On Fri, May 13, 2011 at 10:07 AM, 7stud -- <bbxx789_05ss / yahoo.com> wrote: > Brian Xue wrote in post #998397: > > Thanks all for your kindly explanation. It really helps. > > Here's more: > > class Object > private > > def greet > puts 'hello' > end > end > > class B > end > > puts Object.private_instance_methods.include?(:greet) > puts B.private_instance_methods.include?(:greet) > puts self.singleton_class.private_instance_methods.include?(:greet) > > not_inherited alse > puts > > self.singleton_class.private_instance_methods(not_inherited).include?(:greet) > > > --output:-- > true > true > true > false > > The lookup paths: > > Object > ^ private :greet > | > | > Class B > ^ > | > | > singleton class of b > ^ > | > | > b .new > > > > > > Object > ^ private :greet > | > | > singleton class of 'main' > ^ > | > | > main > > > You really can't determine in which class a method is defined unless you > call the *_methods() with false as the argument, which causes ruby to > ignore inherited methods. > > -- > Posted via http://www.ruby-forum.com/. > > --0015174c4278f9c45004a36e1890--