Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2901
| 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 <fs_tigre@hotmail.com> |
| 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> (permalink) |
| 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 |
Show key headers only | View raw
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/.
Back to comp.lang.ruby | Previous | Next — Next in thread | Find similar | Unroll thread
Understanding global variables. Fily Salas <fs_tigre@hotmail.com> - 2011-04-14 19:55 -0500
Re: Understanding global variables. 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-14 20:05 -0500
Re: Understanding global variables. jake kaiden <jakekaiden@yahoo.com> - 2011-04-14 22:30 -0500
Re: Understanding global variables. Fily Salas <fs_tigre@hotmail.com> - 2011-04-15 08:13 -0500
Re: Understanding global variables. 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-15 13:10 -0500
Re: Understanding global variables. jake kaiden <jakekaiden@yahoo.com> - 2011-04-15 08:36 -0500
Re: Understanding global variables. Fily Salas <fs_tigre@hotmail.com> - 2011-04-15 09:14 -0500
Re: Understanding global variables. jake kaiden <jakekaiden@yahoo.com> - 2011-04-15 09:20 -0500
Re: Understanding global variables. Fily Salas <fs_tigre@hotmail.com> - 2011-04-16 14:47 -0500
csiph-web