David Corbin
2005-Jun-02 10:37 UTC
Don''t use an attribute/column that matches a Kernel method (including ''y'')
I''ve found a problem, and it might be bug in Ruby itself, but I''m not sure. Say I''ve got a model object (Point) whose table contains column "y". Model Circle has_one Point center. When I load a Center from the database, I"m unable to get the actual value for y. Here is a summary of what I see when I debug into Circle.center.y: Stepping into y(), I find myself in association_proxy@method_missing. Makes sense. It calls load_target, and successfully loads a good-looking Point into @target. The code then call @target.send(symbol, *args, &block). When I step into this, I find myself in yaml.rb, Kernel#y. I expected to find myself in active_record/base.rb, method_missing. Now, once you understand that yaml has added a method called ''y" to Kernel, and you understand that Kernel is a bit of special case, it''s easy to imagine how send might "mis-route" this message, rather than calling method_missing. I''m not sure what the best long-term solution is, but my short-term solution is to add this method to Point def y read_attribute(''y'') end David