From: Brian Candler Date: 2009-07-23T06:21:54+09:00 Subject: Re: Instantiating classes / sharing data between classes Trevoke wrote: > I think this is what I want to do (maybe I'm thinking about it wrong): > > a = Doctor.new > b = Doctor.new > > I want both 'a' and 'b' to have access to: > modalities = ['US', 'CR', 'CT', 'MR'] Another option for you: modalities = ['US', 'CR', 'CT', 'MR'] a = Doctor.new(modalities) b = Doctor.new(modalities) i.e. each has an instance variable pointing to the shared object. If you like this approach, you can take it further - see http://onestepback.org/index.cgi/Tech/Ruby/DependencyInjectionInRuby.rdoc Unfortunately, Jim modified his site and didn't carry forward the attachment, and so the link to depinj.rb remains sadly dead. I think I have a local copy floating around somewhere. -- Posted via http://www.ruby-forum.com/.