On Thu, 9 Nov 2006, skt wrote:
Once again, I think you all kindly for your quick response to my “quick”
I need to be patient, but for me it’s all or nothing. I WANT to learn this,
but these frustrating little roadblocks are driving me crazy.
I understand you can define them as self as well?
def self(username, pass, etc, etc)
You have just defined a method called self. This will confuse
the heck out of you later: self refers to the current “instance”
and is often left out in Ruby code. It is an object, not a method.
Basically, don’t do that.
Alright, can somebody point me to a guide that doesn’t leave me all
kinds of confused?
def thingHere(self, params)
In Python and some other languages you make the first parameter of a
method refer to the object. You don’t need to do that in Ruby.
@params = so and so
@params = params
would be the Ruby idiom here. Set the “instance variable” value to the
@params is an “instance variable” – a variable that lives inside
each instance. If you read up on Object Orientation you will find
things about “Has-A” and “Is-A” relationships. An object “Is-A”
Type (which for Ruby is more than just it’s class, because
individual objects can be modified – see the stuff on Duck Typing
when you are ready to know that level of detail.) But in the simple
cases an Object “Is-A” Whatever-its-class-is. However, an object
“Has-A” instance variable, or it has more than one.
My friend’s car Is-A Nissan Micra. It Has-A steering wheel, but
then it Is-A Car, and all Cars have one. (A class is an object and
it can be substituted for its parent class. A Human Is-A Mammal, etc.)