Saiho Yuen
2006-Apr-25 16:24 UTC
[Rails] how can I access a class variable outside of the class???
Hi we wanted to access a class varaible from outside of the same class, like class klass @@var1 end we found out we can not use the class variable like this: klass.var1 we have to create a class function like class klass @@var1 def var1 return @@var1 end end If anyone know how to access a class variable directly without passing by a function??? Thanks you very much Saiho The mind is its own place, and in itself. Can make a Heaven of Hell, a Hell of Heaven. http://www.geocities.com/sayoyo/ __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
hemant
2006-Apr-25 20:25 UTC
[Rails] how can I access a class variable outside of the class???
>From picaxe book:" Class variables are private to a class and its instances. If you want to make them accessible to the outside world, you''ll need to write an accessor method. This method could be either an instance method or, leading us neatly to the next section, a class method. " On 4/25/06, Saiho Yuen <sayoyo@yahoo.com> wrote:> > Hi > > we wanted to access a class varaible from outside of > the same class, like > > class klass > @@var1 > end > > we found out we can not use the class variable like > this: > klass.var1 we have to create a class function like > > > class klass > @@var1 > > def var1 > return @@var1 > end > > end > > > If anyone know how to access a class variable directly > without passing by a function??? > > Thanks you very much > > Saiho > > > > The mind is its own place, and in itself. > Can make a Heaven of Hell, a Hell of Heaven. > > http://www.geocities.com/sayoyo/ > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- nothing much to talk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060425/b531569a/attachment.html
Alex Wayne
2006-Apr-25 20:55 UTC
[Rails] Re: how can I access a class variable outside of the class??
Saiho sayoyo wrote:> Hi > > we wanted to access a class varaible from outside of > the same class, like > > class klass > @@var1 > endTry cattr_accessor :some_var works just like attr_accessor except for class variables. -- Posted via http://www.ruby-forum.com/.