タグ

関連タグで絞り込む (2)

タグの絞り込みを解除

styleとdefに関するkiyo_hikoのブックマーク (1)

  • Structクラスを継承してはいけない(戒め - Bye Bye Moore

    以前書いたStructで構造体なデータを扱う - Bye Bye Mooreという記事で class Point < Struct.new(:x, :y) def +(other_object) Point.new(x + other_object.x, y + other_object.y) end end とか書いていました。 が、公式リファレンスには 無名クラスのサブ クラスを作成する方法でカスタマイズする場合は無名クラスが使用されなくなっ てしまうことがあるためです。 との記述があり上記の方法は推奨されません。 どうしても拡張する必要がある場合 Point = Struct.new(:x,:y) do def +(other_object) Point.new(x + other_object.x, y + other_object.y) end end としてあげるのがよいです。

    Structクラスを継承してはいけない(戒め - Bye Bye Moore
    kiyo_hiko
    kiyo_hiko 2016/01/28
    Clazz < Struct.new(:attribute); def method() ... end; end ではなく Clazz = Struct.new(:attribute) do; def method() ... end; end な感じがいいという話
  • 1
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy