タグ

polyに関するkiyo_hikoのブックマーク (5)

  • how to generate migration to make references polymorphic

    I have a Products table and want to add a column: t.references :imageable, :polymorphic => true I was trying to generate migration for this by doing: $ rails generate migration AddImageableToProducts imageable:references:polymorphic but I am obviously doing it wrong. Can anybody make any suggestion? Thanks When I try to manually put it in after generating the migration, I did it like this: class A

    how to generate migration to make references polymorphic
    kiyo_hiko
    kiyo_hiko 2016/02/25
    create_table :hogera do |t| t.references :poly, polymorphic: true, index: true # => generates poly_type to specify the model name, poly_id to specify the poly's record
  • DRYing Up Polymorphic Controllers

    Polymorphic routes allow drying up the controller implementation when functionality is identical, regardless of entry point. A good example is comments for articles and blogs. There is a challenge to balance the implementation of the comments controller reflecting the multiple incoming routes. Let's look at the way it could be written. Routing is straightforward with blogs and article models actin

  • 『ポリモーフィズム』

    突然ですが、今日はポリモーフィズムについてちょっと書いてみようかなぁ…、なんて思って書いてみました。 Wikipediaの説明には「ポリモーフィズム(Polymorphism)とは、主にオブジェクト指向プログラミングで、あるオブジェクトへの操作が呼び出し側(sender)ではなく、受け手のオブジェクト(receiver)によって定まる特性のこと」とあります。 C++で簡単な例を見てみましょう(ベタな例ですが…)。 class Animal { public: virtual ~Animal() {} virtual std::string get_name() const = 0; }; とまあ、こんなインターフェースがあったとして、Animalに名前を問う関数があるとしましょう。 void ask_name(const Animal& animal) { std::cout << "名前

    『ポリモーフィズム』
  • 4.6.2 Object型によるポリモーフィズム - EXCEL-VBA開発講座

    kiyo_hiko
    kiyo_hiko 2011/07/13
    Object型にSetしてポリモーフィズム
  • ポリモーフィズム - Wikipedia

    ポリモーフィズム(英: polymorphism)とは、それぞれ異なる型に一元アクセスできる共通接点の提供[1]、またはそれぞれ異なる型の多重定義を一括表現できる共通記号の提供[2]を目的にした、型理論またはプログラミング言語理論(英語版)の概念および実装である。この用語は、有機組織および生物の種は様々な形態と段階を持つという生物学の概念からの借用語である[3]。多態性、多相性と邦訳されることが多い。 ポリモーフィズムは、通常以下の三種に分けられる。 アドホック多相 (ad hoc polymorphism) 恣意的な型の集合に一つの共通接点を提供する。関数オーバーロード、Mix-inのいち実装、型クラスなど。 パラメトリック多相 (parametric polymorphism) 詳細化されていない型要素を内包する抽象的な型に記号表現を提供する。ジェネリクスや関数型言語の型構築子など。

    kiyo_hiko
    kiyo_hiko 2011/07/04
    対義語はまんま「モノモーフィーズム」だったのか。ja版を見ると必ずしも動的ではなくて良くて、メソッドのシンボル名が同じなら(オーバーロードとかも)多態と考えていいのかな。謎。en版もあとで読むべきだなあ
  • 1