I have a 2-part question here that's a little tricky and starting to
make my head hurt.
I'm working on a plugin for personal use, where I have an rclients
table (not named clients because of conflicts with another plugin),
and several other models that can have Rclients (polymorphic
association). I've defined a method acts_as_client_entity that will
set up the necessary associations.
Let me first give my functioning code:
############### join model:
class ClientEntityAssociation < ActiveRecord::Base
belongs_to :rclient
belongs_to :entity, :polymorphic=>true
end
The first part of my question is whether there is a way to pass in a
reference to the calling class (klass) without first setting it as a
variable. My understand is that if I used self directly in the
class_eval statement, it would evaluate to Rclient.
Maybe, don't know off hand.
The second part of my questions is why I had to use define_method for
primary_client= (as opposed to def primary_client=). I kept getting
conflicts with the dynamic methods rails created from the statement
I *think* the def method is scoping it inside the proc whereas
define_method is actually evaluating it within the context of the
class_eval (and therefore getting defined as an instance method of the
class).
I highly recommend the O'Reilly book, The Ruby Programming Language
since it gives details about metaprogramming that's rarely found
elsewhere and organized in the same place. There are stuff about how
to access the variable bindings and may answer your first question as
well.