From: Perry Smith Date: 2008-02-01T13:41:47+09:00 Subject: Re: weird binding error ara howard wrote: > On Jan 31, 2008, at 10:33 AM, Perry Smith wrote: > >> # Problem occurs here wrap calls Object#wrap instead >> # of Cached::Base#wrap or Cached::Queue#wrap >> temp.wrap_with_combined > > there really isn't enough code there to say, but i'm guessing you have > a 'has_many' association and are calling 'wrap_with_combined' on a > *Array*, thus defining it on Object intercepts this call. > > perhaps an explanation of what you are trying to do? > > regards. > > a @ http://codeforpeople.com/ Thanks Howard. I found a way to dump out ancestors and I found a thread talking about association proxies. In that thread, it tells to do (from memory) ( class << temp; self; end).ancestors Doing this produces a list of associations and proxies, etc (as you predicted). And Cached::Queue is not in the list. I added wrap and unwrap methods to a couple of the association classes and that solved my problem. I am not yet to what I think is a general solution but I'm at least understanding what is happening at little more. What am I doing? I have a legacy system that is remote called Retain. For each concept, like a PMR, I have three classes. Retain::PMR, Cached::PMR, and Combined::PMR. Retain::PMR goes to retain and gets the data. Cached::PMR is a subclass of ActiveRecord::Base and uses all the normal ActiveRecord features. Combined::PMR is the magic that glues them together. For any request, I look to see if I have it in Cached::PMR. I use time stamps to expire it, etc. If it is there and current, I just present that. If not, I go to Retain::PMR to get the data from Retain and save it in Cached::PMR. All the usual rails code (the controllers and views) work with Combined objects (or thats the idea). Most of the magic is done with method_method and respond_to? so when pmr.owner comes, it goes to a Combined instance's method_missing which (if the cache is deemed valid) is forwarded on to the Cached (ActiveRecord) instance. When the request completes, it is "wrapped" so the result is a Combined instance -- not a Cached instance. Most things, the "wrapped" version is self. For instances of bases which are a subclass of Cached::Base, the wrapped version is the equivalent Combined version. For somethings like Arrays and Hash, the wrap version is an Arrary or Hash with each value wrapped. Right now, my biggest question is how does the association do this magic? I haven't found it yet. Driving home I thought I need to look for places that do things like class << self and other things like that which modify the metaclass of an object. I've been looking at initialize and those things but that hasn't told me anything. But I'm wondering how an object that isn't an Array (to pick an example) says "Array#...." when inspected or when name is called, etc. Thank you for your help -- Posted via http://www.ruby-forum.com/.