self at the end of a method

Hello,

I have a small thing which I dont understand.

If you for example look at the Window_Base class you find methods with the self keyword at the end:

def show self.visible = true self endor in Window_MapName:

def open refresh @show_count = 150 self.contents_opacity = 0 self endMy question is, why is there the self at the end, what does it do?
It means it returns the object back to the calling method... though on the case of those methods above, I don't know why they'd do that...

but then again, that allows things like:

Code:
#Since show returns self, we can do this#after this, x will be equal to the new #instance of MapNamex=Window_MapName.new(parameters).showx.blahblahblah
instead of

Code:
x=Window_MapName.new(parameters)x.showx.blahblahblah
Just remember this: the methods will return whatever it is on the last line
Ahh ok, thank you very much.

Now its clear to me why you would return the self.
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/self-at-the-end-of-a-method.25732/