David Thiel wrote:
> I'm just working on learning ruby, and was trying to write a simple
> chatserver, but I guess I'm not understanding how the interpreter tells the
> difference between methods and attributes.  I have an array full of users,
> each one of which has the socket they're connected on as an attribute.  When
> I try and do something simple like "puts users.last.socket" to check and see
> if the socket was assigned properly, it complains that there's no such
> method as socket - I was expecting it to print the socket property.  I may
> just be missing something obvious here, this is how I did it in python.  Any
> help would be appreciated.

Outside of the object's namespace, you can't use @socket,. You have to
have accessor methods (reader and/or writer) for other namespaces to
refer to the attr.

This is easy to do; put one of these lines in your user class:

  attr_reader :socket
  attr_writer :socket
  attr_accessor :socket   # both r and w

Then you can use 'users.last.socket' if you have a reader and
'users.last.socket = ' if you have a writer.

--
Joel VanderWerf                          California PATH, UC Berkeley
mailto:vjoel / path.berkeley.edu                     Ph. (510) 231-9446
http://www.path.berkeley.edu                       FAX (510) 231-9512