G
Gareth Adams
Hi guys,
First the pastie, I got class_eval from #ruby-lang on freenode -
http://pastie.caboo.se/127003
I've commented out the Rails specific stuff so I'm sure this is a Ruby question.
What I'm trying to do is have a per-subclass variable created by a class method
on the super class (which is called from the subclass). Fun.
When I load in the file above I get
-- Processor::Sponge.related_questions
=> {:surname=>1, :email=>1, :location=>1, hone_number=>1, :forename=>1}
-- Processor::CampaignMonitor.related_questions
=> {:surname=>1, :email=>1, :location=>1, hone_number=>1, :forename=>1}
-- Processor::Base.related_questions
=> {:surname=>1, :email=>1, :location=>1, hone_number=>1, :forename=>1}
where the expected output is
-- Processor::Sponge.related_questions
=> {:location=>1, hone_number=>1}
-- Processor::CampaignMonitor.related_questions
=> {:surname=>1, :email=>1, :forename=>1}
-- Processor::Base.related_questions
=> {} # possibly nil, it's not too important as it shouldn't be called directly
I'll be the first to admit I don't really understand class variables, is what
I'm trying to do possible without having to add anything to the subclass?
First the pastie, I got class_eval from #ruby-lang on freenode -
http://pastie.caboo.se/127003
I've commented out the Rails specific stuff so I'm sure this is a Ruby question.
What I'm trying to do is have a per-subclass variable created by a class method
on the super class (which is called from the subclass). Fun.
When I load in the file above I get
-- Processor::Sponge.related_questions
=> {:surname=>1, :email=>1, :location=>1, hone_number=>1, :forename=>1}
-- Processor::CampaignMonitor.related_questions
=> {:surname=>1, :email=>1, :location=>1, hone_number=>1, :forename=>1}
-- Processor::Base.related_questions
=> {:surname=>1, :email=>1, :location=>1, hone_number=>1, :forename=>1}
where the expected output is
-- Processor::Sponge.related_questions
=> {:location=>1, hone_number=>1}
-- Processor::CampaignMonitor.related_questions
=> {:surname=>1, :email=>1, :forename=>1}
-- Processor::Base.related_questions
=> {} # possibly nil, it's not too important as it shouldn't be called directly
I'll be the first to admit I don't really understand class variables, is what
I'm trying to do possible without having to add anything to the subclass?