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/.