From: Bjorn Pettersen Date: 2002-01-03T00:08:06+09:00 Subject: [ruby-talk:30043] Re: Ruby/Python: Software Engineering > From: Rich Kilmer [mailto:rich@infoether.com] > > > -----Original Message----- > > From: Bjorn Pettersen [mailto:BPettersen@NAREX.com] > > Sent: Monday, December 31, 2001 6:09 PM > > To: ruby-talk ML > > Subject: [ruby-talk:29910] Re: Ruby/Python: Software Engineering > > > > > > > From: Kyle Cordes [mailto:kyle@kylecordes.com] > > > > > > "Mathieu Bouchard" wrote in message > > > news:Pine.LNX.4.21.0112311600250.3187-100000@bartok... > > > > > > > > Enforced indention (you indent your own code I bet) > > > > > > > That's a nice feature to save writing "end" all the > time. But not > > > having > > > > to write "self" all the time is much more important to me. > > > > > > That's always been a mystery to me... I enjoy Python's terseness > > > that comes from using indentation to describe blocks, but > it doesn't > > > seem to reconcile with the (IMHO) sillyness of writing self > > > everywhere. > > > > You need some way of disambiguating nested classes (how > does Ruby do > > this btw?): > > > > class Outer: > > def method1(self): pass > > def method2(self): > > class Inner: > > def innerMeth1(this): pass > > def innerMeth2(this): > > self.method1() > > this.innerMeth1() > > In this example is class Inner defined in the method2 body? Yes, and you can e.g. return it as a class-instance from that body (i.e. it's both a true inner-class, and a true-object). > In Ruby you can do this: > > class Outer > def method1 > end > > class Inner > def innerMethod1 > end > end > end > > but the Inner class is NOT an inner class (a la Java) but a > class defined in the namespace Outer and referenced as: > > in = Outer::Inner.new > in.innerMethod1 I see. In Python you would achieve that by putting the definition of Inner in the scope of Outer (instead of method2). > Now, that class does not have access to the methods on Outer > (unless they are class methods like: > > class Outer > def Outer.method1 > end > end > > Then the innerMethod1 can execute the class method as: > > class Inner > def innerMethod1 > Outer.method1 > end > end > > Or if Inner is a subclass of Outer you could do this: > > class Outer > def method1 > end > > class Inner < Outer > def innerMethod1 > method1 > end > end > end Interesting. -- bjorn