This article was migrated from http://rails.office.drecom.jp/takiuchi/archive/147

西さん(a.k.a. maiha)のRuby on Rails入門のp112に書かれてる偽STIが面白そうだったので、 instantiateのソースコードをメモ。

# File src/rails-1.1.6/activerecord/lib/active_record/base.rb, line 975
def instantiate(record)
  object = 
    if subclass_name = record[inheritance_column]
      if subclass_name.empty?
        allocate
      else
        require_association_class(subclass_name)
        begin
          compute_type(subclass_name).allocate
        rescue NameError
          raise SubclassNotFound,
            "The single-table inheritance mechanism failed to locate the subclass: '#{ record[inheritance_column] }'. " +
            "This error is raised because the column '#{ inheritance_column }' is reserved for storing the class in case of inheritance. " +
            "Please rename this column if you didn't intend it to be used for storing the inheritance class " +
            "or overwrite #{ self.to_s }.inheritance_column to use another column for that information."
        end
      end
    else
      allocate
    end

  object.instance_variable_set("@attributes", record)
  object
end
ソースコードはここから持ってきました。

This article was migrated from http://rails.office.drecom.jp/takiuchi/archive/147

posted by genki genki on Fri 29 Dec 2006 at 13:02 with 0 comments
Contents rssrss
光ファイバーを二次元振動させて走査するAR用ディスプレイ
因果の取り違え
Swift2's defer for CoffeeScript
mongodb-3.0からcreateIndexのdropDupsが無くなったらしい
mongodb-3.0以降のWiredTigerの設定を動的に変更する方法
一般楕円の高速生成アルゴリズムへの道標
farro mantecatoのレシピ
Droonga関連の記事のまとめ
RuntimeErrorの特定のメッセージに限定してrescueする方法
jQueryでscriptタグを実行せずにappendする
Tags
coffeescriptdefergroongajsmemonodenodejs
Comments rssrss
瀧内元気 瀧内元気: MacOS版は以下にあります genki/ViMouse 01/16 05:40
dsjf dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これでも出... 01/08 23:23
瀧内元気 瀧内元気: おお、チェックしてみます。thx! 12/24 05:23
overisland overisland: Reeder for iPhone もこの UI を実装していますね。 12/24 05:13
瀧内元気 瀧内元気: その情報は見たのですが、以下のサイトによると、現在はまた必要になってるっぽいんですよね。 http:... 12/01 12:20
tkawa tkawa: http://devcenter.heroku.com/articles/rails31_herok... 12/01 10:47
瀧内元気 瀧内元気: どもー。いまはgithubに置いてあります https://github.com/genki/irb... 07/10 08:31
ともち ともち: こんにちは! すばらしいプログラムをありがとうございます。しかし、merbiのドメイン、切れているみ... 07/10 02:30
Services from s21g
天気ランキング
複数の天気予報サービスの予報と観測結果を比較。週間・月間・年間・通期のランキングや地域別の予報比較から、自分に合う天気予報を探せます。
MagicBag
MagicBagは、Cloudflare R2やS3互換ストレージをMacのFinderから扱えるファイル同期クライアントです。
アンテナショップめぐり
東京にある全国のアンテナショップ、イベント、特産品を地図や条件から探せるサービスです。
YOMU Web小説リーダー
YOMUは、Web小説の読み上げに特化したiPhoneアプリです。
補助探
公開されている補助金・助成金情報を集約し、条件に合う制度を探しやすくするサービスです。