Re: Ruby Basics / define met;hod



On 06.03.2008 17:18, Chinna Karuppan wrote:
I did read through your reply.especially this....
"Inside a class body /self/ is the class instance being defined right
now."
I still could not understand.

You wondered why define_method can be invoked inside class...end because it is private and should not be accessible "from outside". Private methods can normally be only invoked without an explicit receiver, i.e. only on /self/. I explained and demonstrated (via the printing) that inside class...end /self/ is actually the class being defined. Hence you can invoke define_method inside class..end. q.e.d.

Then I went on to explain that /private/ in Ruby is rather weak because you can invoke private methods on any instance simply by going through /send/.

Cheers

robert
.



Relevant Pages

  • Re: ByRef doesnt make it across invoke?
    ... how Invoke itself is defined... ... string 'Failed' ... Private Shared StaticString As String ... Private Sub Form1_Load(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Newbie question : private / public methods
    ... private method `privateMethod' called for ... Ruby implements private methods as methods which can't be called using an ... implicit receiver. ... this ensures that private instance methods can only be called ...
    (comp.lang.ruby)
  • Re: Private methods cant be overridden?
    ... most virtual methods public, or make most of them private. ... private methods should be independent of anything the derived class does. ...
    (comp.lang.java.programmer)
  • Re: WM_KEYDOWN, WM_CHAR and WM_KEYUP
    ... Its not too 'safe' (private methods could change) but possible. ... If you use Reflector you can see methods like: ... Whatever is the active focused window it gets the keys. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Testing private methods
    ... Thomas Mlynarczyk wrote: ... It is private to the class and not meant to be called from outside. ... to know exactly what they're doing) might need a direct access to private methods and for that a decorator would, IMHO, be the perfect solution. ... Thus it is imperative to have some kind of "meta-law" which makes sure that a law will do no harm in an unforeseen situation and can be ignored if such a situation arises. ...
    (comp.lang.php)