I’ve done some Python but have just now starting to use Ruby
I could use a good explanation of the difference between ‘self’ in these two languages.
Obvious on first glance:
Self is not a keyword in Python, but there is a ‘self-like’ value no matter what you call it.
Python methods receive self as an explicit argument, whereas Ruby does not.
Ruby sometimes has methods explicitly defined as part of self using dot notation.
Initial Googling reveals
http://rubylearning.com/satishtalim/ruby_self.html
http://www.ibiblio.org/g2swap/byteofpython/read/self.html
Python is designed to support more than just object-oriented programming. Preserving the same interface between methods and functions lets the two styles interoperate more cleanly.
Ruby was built from the ground up to be object-oriented. Even the literals are objects (evaluate 1.class and you get Fixnum). The language was built such that self is a reserved keyword that returns the current instance wherever you are.
If you’re inside an instance method of one of your class, self is a reference to said instance.
If you’re in the definition of the class itself (not in a method), self is the class itself:
At class definition time, ‘I am a C’ will be printed.
The straight ‘def’ defines an instance method, whereas the ‘def self.xxx’ defines a class method.