Permalink
Browse files

Added is_a_superclass. Thanks again Eric!

git-svn-id: svn+ssh://svn0.sea.apvio.net/home/rwl4/inherits_from@5 bd10a536-b517-0410-99c0-c9a68740b5c0
  • Loading branch information...
1 parent 71c5092 commit d1708e186822c07f1d500fe4fbe29d96c23ba40e rwl4 committed Apr 25, 2007
Showing with 7 additions and 1 deletion.
  1. +7 −1 lib/inherits_from.rb
View
@@ -82,12 +82,18 @@ def self.inherits_from(association_id, options = {})
before_update(before_callback)
end
+ def self.is_a_superclass
+ define_method('subobject') do
+ subtype.constantize.send("find_by_#{self.class.name.downcase}_id", send("id"))
+ end
+ end
+
private
# Ensures that there is an association to access, if not, creates one.
def init_inherited_assoc(association_id)
if new_record? and instance_variable_get("@#{association_id}").nil?
send("build_#{association_id}")
- instance_variable_get("@#{association_id}").type = self.class.to_s
+ instance_variable_get("@#{association_id}").subtype = self.class.to_s
end
end
end

0 comments on commit d1708e1

Please sign in to comment.