From: "Mauricio Fernández" Date: 2002-11-12T05:55:26+09:00 Subject: Re: What the...? On Tue, Nov 12, 2002 at 05:47:02AM +0900, Johan Persson wrote: > Take a look on the snippet below > > # points is an array of structure-objects defining a point > points[0].x = 5 > points[0].y = 4 > 1.upto(points.length) { |i| > points[i].x = points[i-1].x > points[i].y = points[i-1].y > } > > Now that looks like a legal bunch of statements, right? The thing is > every time Ruby interpret the line 'points[i].x = points[i-1].x' it > stops, giving me nothing but a cryptic error message, 'undefined > method `x=' for nil (NameError)'. > Could someone please tell me what's going on? Easy one; when you do points[i].x=... you're calling the 'x=' method of the points[i] object, which happens to be nil, for points[1] == nil. You're thinking in C++ or Java; Ruby uses accessors. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Whoa...I did a 'zcat /vmlinuz > /dev/audio' and I think I heard God... -- mikecd on #Linux