Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #4455
| From | 7stud -- <bbxx789_05ss@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: where does the pure method defined when starting irb |
| Date | 2011-05-12 21:07 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <b8c302fbff98c1f2edefabb50e688446@ruby-forum.com> (permalink) |
| References | <BANLkTi=rQN7E75h4zWxOi8WdhqD_reBbAA@mail.gmail.com> <BANLkTinXr6CBdY+5Q=_iMtUheG3EZ9GoCA@mail.gmail.com> <b6130c2d57835d754af54499c4503921@ruby-forum.com> <BANLkTim+dK3dSgmJ=xMfbGK_UDSXOw_wyg@mail.gmail.com> |
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/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
where does the pure method defined when starting irb Brian Xue <brxue.cn@gmail.com> - 2011-05-12 04:40 -0500
Re: where does the pure method defined when starting irb jake kaiden <jakekaiden@yahoo.com> - 2011-05-12 06:17 -0500
Re: where does the pure method defined when starting irb Christopher Dicely <cmdicely@gmail.com> - 2011-05-12 09:57 -0500
Re: where does the pure method defined when starting irb Michael Edgar <adgar@carboni.ca> - 2011-05-12 10:12 -0500
Re: where does the pure method defined when starting irb 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-12 14:00 -0500
Re: where does the pure method defined when starting irb Brian Xue <brxue.cn@gmail.com> - 2011-05-12 18:57 -0500
Re: where does the pure method defined when starting irb 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-12 21:07 -0500
Re: where does the pure method defined when starting irb Brian Xue <brxue.cn@gmail.com> - 2011-05-16 19:54 -0500
Re: where does the pure method defined when starting irb Michael Edgar <adgar@carboni.ca> - 2011-05-16 20:00 -0500
Re: where does the pure method defined when starting irb Brian Xue <brxue.cn@gmail.com> - 2011-05-16 21:24 -0500
Re: where does the pure method defined when starting irb 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-12 18:58 -0500
Re: where does the pure method defined when starting irb 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-12 13:21 -0500
Re: where does the pure method defined when starting irb 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-12 13:53 -0500
csiph-web