From: Jonan Scheffler Date: 2012-05-27T21:39:49+09:00 Subject: Re: Am I justified to use a global variable if it must be used in all scopes? --0016e6d644e892d24604c103e595 Content-Type: text/plain; charset=ISO-8859-1 Perhaps a singleton class? It seems to me that you're probably in need of some more abstraction if you feel you need a global variable. On May 27, 2012 8:34 AM, "Phil Stone" wrote: > Hello, > Ever since I started learning Ruby, I've been strongly discouraged > from using global variables > (http://www.caliban.org/ruby/rubyguide.shtml#style) > (http://www.ruby-forum.com/topic/187685#819233). > > In a program I'm making, I have a variable (which stores an instance of > a class) that is declared outside of any functions or classes. However, > I need to be able to call its methods from various class and function > scopes, and nothing but a global variable would let me do that. This > variable is simply what the program is centered around, and must be > accessed and edited by various classes. I'm not sure why a global > variable would be such a bad habit in this case, especially since it is > only one. > > Can I justify using it? > > -- > Posted via http://www.ruby-forum.com/. > > --0016e6d644e892d24604c103e595 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Perhaps a singleton class? It seems to me that you're probably in ne= ed of some more abstraction if you feel you need a global variable.

On May 27, 2012 8:34 AM, "Phil Stone" = <lists@ruby-forum.com> wr= ote:
Hello,
Ever since I started learning Ruby, I've been strongly discouraged
from using global variables
(http://www.caliban.org/ruby/rubyguide.shtml#style)
(http://www.ruby-forum.com/topic/187685#819233).

In a program I'm making, I have a variable (which stores an instance of=
a class) that is declared outside of any functions or classes. However,
I need to be able to call its methods from various class and function
scopes, and nothing but a global variable would let me do that. This
variable is simply what the program is centered around, and must be
accessed and edited by various classes. I'm not sure why a global
variable would be such a bad habit in this case, especially since it is
only one.

Can I justify using it?

--
Posted via http://= www.ruby-forum.com/.

--0016e6d644e892d24604c103e595--