This article was migrated from http://rai
西さん(a.k.a. maiha)のRuby on Rails入門のp112に書かれてる偽STIが面白そうだったので、
instantiat
# File src/rails-ソースコードはここから持ってきました。1.1.6/acti verecord/l ib/active_ record/bas e.rb, line 975 def instantiat e(record) object = if subclass_n ame = record[inheritanc e_column] if subclass_n ame.empty? allocate else require_as sociation_ class(subclass_n ame) begin compute_ty pe(subclass_n ame).allocate rescue NameError raise SubclassNo tFound, "The single-tab le inheritanc e mechanism failed to locate the subclass: '#{ record[inheritanc e_column] }'. " + "This error is raised because the column '#{ inheritanc e_column }' is reserved for storing the class in case of inheritanc e. " + "Please rename this column if you didn't intend it to be used for storing the inheritanc e class " + "or overwrite #{ self.to_s }.inheritan ce_column to use another column for that informatio n." end end else allocate end object.ins tance_vari able_set("@attributes ", record) object end
This article was migrated from http://rai
posted by
genki
on Fri 29 Dec 2006
at 13:02