From: Mark Somerville Date: 2007-06-19T21:46:26+09:00 Subject: Re: Class variables in class_eval On Tue, Jun 19, 2007 at 09:05:38PM +0900, Robert Dober wrote: > Look at this slightly adapted code just using Class Instance Variables. > Does this solve your problem? It does! I wasn't aware that there are class instance variables as well as class variables. Appreciated, thank you very much! Mark > > -------------------------8<---------------------------- > > module HostBasedCache > > def setup_cache(method, &method_proc) > @cache_method = method_proc if block_given? > class_eval <<-METHOD > def self.#{method}(param) > #some stuff not relevant > puts @cache_method.call(param) > #some stuff not relevant > end > METHOD > end > end > > class MyObject > > extend HostBasedCache > setup_cache(:find_with_roles) do |id| > # User.find_by_id(id, :select => "users.id, roles.id", :include => [ :roles > ]) > puts "Hi there " << id.to_s > end > > end > > > MyObject.find_with_roles( 42 ) > > -------------------------8<---------------------------- > Cheers > Robert > -- > You see things; and you say Why? > But I dream things that never were; and I say Why not? > -- George Bernard Shaw