I have two classes with class variables. One of them derives from active
record, the other one does not. I initialize both members to NULL, then
lazy-instantiate them. The class which does not derive from active
record preserves the value correctly. The class which does derive from
active record always seems to be re-setting it to NULL.
class Class1 ## @@thelist holds the initialized value
@@thelist = nil
attr_accessor :name, :id
def self.retrieveall
if @@thelist.nil?
@@thelist = Array.new
entry = Locale.new
entry.id = "en"
entry.name = "english"
@@thelist << entry
//repeat to populate
end
@@thelist
end
end
class Class2 < ActiveRecord::Base
## anytime retrieveall is called @@thelist is always NULL. Why?
@@thelist = nil
attr_accessor :name, :id
def self.retrieveall
if @@thelist.nil?
@@thelist = Class2.all
end
@@thelist
end
end
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.