3 ms·
Compared to (...)Python-lambas, Ruby's blocks don't introduce another scope. "self" and "return" still refer to the method's scope 'self' in Python still refer
by icebraining 14y ago
Compared to (...)Python-lambas, Ruby's blocks don't introduce another scope. "self" and "return" still refer to the method's scope
'self' in Python still refers to the method's scope too (if the lambda is inside one).
class A(object):
def b(self):
self.name = "John"
c = lambda: "Hello, %s" % self.name
print c()
A().b() #prints "Hello, John"
- TylerE 14y agoStrictly speaking that's merely a convention. Python simply has explicit method receivers. There's nothing pretty you from calling it `obj` or `foobaz` or whatever - it's just a normal variable.