X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!talisker.lacave.net!lacave.net!not-for-mail From: Fily Salas Newsgroups: comp.lang.ruby Subject: Understanding global variables. Date: Thu, 14 Apr 2011 19:55:08 -0500 Organization: Service de news de lacave.net Lines: 49 Message-ID: <962f80bb11f2292d2ba5498cbfca785c@ruby-forum.com> NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1302829367 17435 65.111.164.187 (15 Apr 2011 01:02:47 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Fri, 15 Apr 2011 01:02:47 +0000 (UTC) X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 381591 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: <962f80bb11f2292d2ba5498cbfca785c@ruby-forum.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:2901 Hi, I thought that I understood the different type of variables in Ruby but now that I'm actually trying them I see that I didn't, reading is easy putting things in practice is hard. class Car @mil_gal = 30 @fuel_gal = 10 def go(mil_gal, fuel_gal) @mil_gal = mil_gal @fuel_gal=fuel_gal millage =@mil_gal * @fuel_gal puts millage end end car = Car.new car.go(10,50) In the above code I have two global variables @mil_gal = 30 and @fuel_gal = 10, well let me rephrase this in my eyes they are global variables... but if I change them to mil_gal = 30 and fuel_gal = 10 they actually work. If what I have here are not global variables can someone explain this a little bit? I thought that by adding @ it would make it global and since I can use this inside other defs I was assuming that they were? class Car mil_gal = 30 fuel_gal = 10 def go(mil_gal, fuel_gal) mil_gal = mil_gal fuel_gal=fuel_gal millage =mil_gal * fuel_gal puts millage end end car = Car.new car.go(10,50) Thanks a lot -- Posted via http://www.ruby-forum.com/.