From: Austin Ziegler Date: 2002-12-04T22:13:57+09:00 Subject: Re: Ruby Book for People Who Aren't (Yet) Programmers On Wed, 4 Dec 2002 08:48:18 +0900, Martin DeMello wrote: > An object is the fundamental unit of data storage in Ruby. A Ruby > object consists of I would agree, in part, with Mauricio's suggestion. In many ways, I think it's okay to say: An object is the fundamental unit in Ruby. Objects can represent numbers, text (called /String/s), collections of objects (called /Array/s and /Hash/es), or just about anything else. In Ruby, an object has the following characteristics: > 1. An ID. This is a number Ruby assigns to the object when it is > created, and uses to keep track of the object. Every object has > its own unique ID. Since Ruby takes care of the bookkeeping > details behind the scenes, we don't need to bother with the object > ID ourselves, but it is a useful handle to grasp mentally when we > want to think about a given object. I wouldn't talk about the ID itself as the characteristic. Ruby objects have uniqueness. How it has the uniqueness isn't necessary when introducing objects for the first time. * Uniqueness. Two objects may have the same values and behaviours; they will still be unique objects. Note that I don't address the special case of Fixnum here. > 2. A value. This is the data stored in the object. Examples > include numbers like 1, -2 and 3.14, and strings like "Hello > World". A value can also be a more complex entity, like a set of > numbers, or a collection of several pieces of data. * Value. Most objects will represent values, such as numbers like 1, -2, and 3.14, or text strings like "Hello, World." Objects can also have complex or composite values, like a set of numbers or a collection of several pieces of data. > 3. A set of /methods/. A method is a function that acts on an > object's data, and returns another object. [Damn, this is hard. > What's a 'function'? What does 'return' mean?] In a sense, the > value represents the set of things an object /knows/, and the > methods represent the set of things it can /do/. To get an object > to do something, you /call/ one of its methods; this will give you > back another object (known as the method's 'return value'). > Methods are called using the syntax object.method_name. An example > should make this clear - when we say "Hello World".reverse we are > calling the "reverse" method of the object "Hello World". This > returns another object, in this case "dlroW olleH". * Behaviour. Objects define /methods/, which are ways that programs can interoperate with the object. Methods may accept additional data and provide the results of the method (called a return value). In a sense, the value represents the set of things an object knows, and the methods represent the set of things an object can do. To get an object to do something, you call (or invoke) one of its methods. A method call looks like object.method_name. If we say "Hello World".reverse, we are calling the "reverse" method of the String object "Hello World". The result of this will be another String object, "dlroW olleH". > 4. A /type/. Ruby has several basic types of object. A type is a > collection of methods, so that if two objects have the same type, > they will have the same methods (though their values might be > different). Some of Ruby's fundamental types are Fixnum > (integers), Float (floating point numbers) and String (text > strings). I agree with Mauricio here -- don't introduce type. If my suggested modifications are used, we've noted that objects are unique, have behaviour, and have value. Class can then be introduced as a "template" or "pattern" for object behaviours and values. I can create a unique object based on the template of a class ... -austin -- Austin Ziegler, austin@halostatue.ca on 2002.12.04 at 07.50.54