From: dblack@... Date: 2007-01-26T09:21:30+09:00 Subject: Re: Ruby language question ---2049402039-982185925-1169770884=:24160 Content-Type: MULTIPART/MIXED; BOUNDARY="-2049402039-982185925-1169770884=:24160" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---2049402039-982185925-1169770884=:24160 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Fri, 26 Jan 2007, Stefano Crocco wrote: > Alle 01:02, venerd=C3=AC 26 gennaio 2007, Neville Franks ha scritto: >> Hi, I've been working on adding Ruby language support to our IDE "ED for >> Windows" the past few weeks and am stuck understanding the marked >> statement in this code: >> >> module Mod >> def size >> @size >> end >> def size=3D(val) # what does this mean >> @size =3D val >> end >> end >> >> None of the reference material I've found so far shows this. I saw it in >> the documentation for: attr(symbol, writable=3Dfalse) =3D> nil >> >> Thanks, >> Neville > > def size=3D(val) is simply the definition of a method called size=3D, whi= ch > accepts the parameter val. It's the ruby way of allowing write access to = an > instance variable. I'd put a slightly different spin on it. Ruby lets you put a final =3D on method names, and gives you the nice calling syntax: obj.x =3D 1 # prettified version of obj.x=3D(1) The existence of the =3D-methods doesn't pertain directly to instance variables. You could write: def call_me_ishmael @name =3D "Ishmael" end and you could also write: def name=3D(name) puts "You can't name me!" end and so on. Lots of =3D-methods (including all of those created with attr_writer) involve writing to instance variables; but that's a conventioned layered on top of the way it works, rather than being the way it works itself. David --=20 Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com) ---2049402039-982185925-1169770884=:24160-- ---2049402039-982185925-1169770884=:24160--