タグ

overrideに関するkiyo_hikoのブックマーク (8)

  • Perl の関数をオーバーライドする

    一時的なオーバーライド (Foo.pm) package Foo; use strict; use warnings; sub bar { my $baz = shift; $baz * 2; } 1; (hoge.pl) #!/usr/bin/perl use strict; use warnings; use Perl6::Say; use Foo; say Foo::bar(3); # 6 { no warnings 'redefine'; local *Foo::bar = sub { my $baz = shift; $baz ** 2; }; say Foo::bar(3); # 9 } say Foo::bar(3); # 6 関数を、local で一時的に上書きする。 no warnings 'redefine'; は関数の再定義を許してね、という宣言。 no warnin

    Perl の関数をオーバーライドする
    kiyo_hiko
    kiyo_hiko 2023/06/26
    既存の関数を乗っ取るとき「*Package::method = sub { "code ref." }」するって話。更に自分の場合、特定のときにオーバライド前の関数呼びたくなった→試した結果これは先に「*Backup::method = \&Package::method」でできることがわかった
  • How to override a column in Rails model?

  • How do I add 'each' method to Ruby object (or should I extend Array)?

    I have an object Results that contains an array of result objects along with some cached statistics about the objects in the array. I'd like the Results object to be able to behave like an array. My first cut at this was to add methods like this def <<(val) @result_array << val end This feels very c-like and I know Ruby has better way. I'd also like to be able to do this Results.each do |result| r

    How do I add 'each' method to Ruby object (or should I extend Array)?
    kiyo_hiko
    kiyo_hiko 2016/04/26
    参考になった。CSVとか読み込むクラスで固有のeach書いたinterface作ってミクシンしてparseとかkconv考えなくて済むようにした
  • ActiveRecord::Base

    Active Record Active Record objects don’t specify their attributes directly, but rather infer them from the table definition with which they’re linked. Adding, removing, and changing attributes and their type is done directly in the database. Any change is instantly reflected in the Active Record objects. The mapping that binds a given Active Record class to a certain database table will happen au

  • エラーページ - 産経ニュース

    ページが存在しません 指定されたURLは存在しませんでした。 5秒後に産経ニューストップページへ移動します。 産経ニューストップへ

  • abstractなstaticメソッド - クラスAを継承してクラスA1、クラスA2を作ろうとしています。Aは抽象クラスまた... - Yahoo!知恵袋


    abstractstatic AA1A2A staticA A1.func()"a1"A2.func()"a2" staticabstractinterface staticA    static
    abstractなstaticメソッド - クラスAを継承してクラスA1、クラスA2を作ろうとしています。Aは抽象クラスまた... - Yahoo!知恵袋
    kiyo_hiko
    kiyo_hiko 2013/05/02
    静的メソッドは言語仕様として継承できない話。Java屋ならピアソンだかの分厚い言語仕様買って読むけどそうじゃないからやりたいこととして優先度が低い…
  • 今の20代はなぜお金がなくても幸せなのか(1/4ページ) | ニコニコニュース


    調20112073.520
    kiyo_hiko
    kiyo_hiko 2013/04/07
    ぬるま湯で育ってきた人間の理論。この理論で貧しい育ちで苦労してきた人間まで一括りに、「金無くても幸せ」とか明後日の方向から勝手に再定義されたなら本当に糞。
  • override prototype

    kiyo_hiko
    kiyo_hiko 2011/10/19
    Perlのプロトタイプは、高階関数でのブロック記法以外のメリットがわからないな。なんか不自然なコードのにおいがして気になるが、あとでちゃんと読もう。ちなみにプロトタイプでのオーバーロードはやっぱり無理(X-P)
  • 1