From: 7stud -- Newsgroups: comp.lang.ruby Subject: Re: where does the pure method defined when starting irb Date: Thu, 12 May 2011 21:07:29 -0500 Organization: Service de news de lacave.net Lines: 69 Message-ID: References: NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1305252732 50822 65.111.164.187 (13 May 2011 02:12:12 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Fri, 13 May 2011 02:12:12 +0000 (UTC) In-Reply-To: X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 383171 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!feed.ac-versailles.fr!talisker.lacave.net!lacave.net!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:4455 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 = false 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 = 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/.