dblack / superlink.net wrote:
> Overall it looks good to me (though I say that as a Python
> know-nothing -- mainly focusing on the Ruby stuff).  There's one
> example I think is misleading:
> 
>   Private attribute x of class A in Ruby:
> 
>   class A
>     def initialize; @x = 0; end
>   end
>   a = A.new; a.x = 1   # exception!
> 
> The problem here is that there is no method x, private or otherwise.

Well, that's kind of the point. These slides don't attempt to explain
everything in detail (otherwise there'd be a lot more of them). That's
my job as a lecturer. I don't want to make myself superfluous. :)


> (This might also have implications for the equivalence you draw
> between"self.attribute" in Python and "@attribute" in Ruby, but I'm
> not sure exactly what's going on on the Python side there.)

'self' is the first parameter in a Python method. Because Ruby doesn't
do things this way, (perhaps something I should note on the slides),
it has to define 'self' as a special constant, but also has the @
prefix as a shortcut (for 'self.').

class A:
  def method(self, arg0, arg1, ..., argN):
    self.x = something

a = A()
a.method(1,2,3) # arg0, arg1, arg2 = 1,2,3

</python><ruby>

class A
  def method(arg0, arg1, ..., argN)
    @x = something
    self.x = something # also valid
  end
end

-- 
Greg McIntyre
greg / puyo.cjb.net
http://puyo.cjb.net