オーバーライド オーバーライドとはスーパークラスにおいて定義されているメソッドを、サブクラス内で再定義することを言います。スーパークラスのメソッドを変更することはできないが、サブクラスに特化した機能を付与したい場合に使用します。 オーバーライドを定義する際には以下の規定があります。 オーバーライドする側はオーバーライドされる側と戻り型、メソッド名、引数型、引数の数が同じでなければなりません。どれか一つでも異なる場合はオーバーライドとは見なされません。 オーバーライドされる側のメソッドに指定されるアクセスレベルより厳しい制限を持つアクセスレベルをオーバーライドする側のメソッドに付与することはできません。例えばオーバーライドされる側のメソッドにprotectedが指定されている場合、オーバーライドする側のメソッドにprivateを指定することはできません。 オーバーライドされる側のメソッドに指
■ [ruby][event] Ruby勉強会@関西-16「30分でわかるcallccの使い方」 先週末のRuby勉強会@関西で、Rubyにおけるcallccの使い方について発表させていただきました。 スライド: pdf ppt 継続の説明については「なんでも継続」がよく参照されるんだけど、 ちょっと説明がボトムアップすぎると思うので(僕も最初に読んだときは全然分からなかった)、「callccで何ができるか」という応用面から攻める 構成にしてみました。 最初は「継続かわいいよ継続」「それをすてるなんてとんでもない」と思ってたんだけど、 いろいろ調べてるうちになんでcallccが嫌われるのかが理解できてしまった。callccはかわいいけど、非常に手のかかる奴らしい。 しかも、面白い利用例はいっぱいあるけど実用的な例があんまりないんだよね^^;。 callccが無くなるとRubyの「かっこよさ
日本Rubyの会 公式Wiki - 第32回 Ruby勉強会@関西 に行ってきました.なんだかんだでひさびさのRuby勉強会でたのしかった! 運営のみなさまおつかれさまでした. 勉強会に行くと,普段得られない刺激がいろいろ得られて良いですね.日常生活はパターンに押し込めがちでだれてくるので,定期的に非日常に自分をもってくのは,精神衛生上よろしいです. 全般的な詳細については,日本Rubyの会 公式Wiki - 第32回 Ruby勉強会@関西の続々よせられるであろうトラックバックや(とおもったらなんか無効になってる),いっしょに行っていっしょにさくさく迷った,id:hitode909くんの第32回 Ruby勉強会@関西に行った - hitode909の日記というエントリを参照してみてください. 今回はサイロスさんのFiberについてのセッションがおもしろかったので,Fiberについていろいろ
ジェネリック(総称あるいは汎用)プログラミング(英: generic programming)は、具体的なデータ型に直接依存しない、抽象的かつ汎用的なコード記述を可能にするコンピュータプログラミング手法である。 ジェネリックプログラミングはデータ型でコードをインスタンス化するのか、あるいはデータ型をパラメータとして渡すかということにかかわらず、同じソースコードを利用できる[1]。ジェネリックプログラミングは言語により異なる形で実装されている。ジェネリックプログラミングの機能は1970年代にCLUやAdaのような言語に搭載され、次にBETA、C++、D、Eiffel、Java、その後DECのTrellis/Owl言語などの数多くのオブジェクトベース (object-based) およびオブジェクト指向 (object-oriented) 言語に採用された。 1995年の書籍デザインパターン[
Documenting my experiences as I struggle to understand Ruby on Rails (Ruby version 1.8.6 tp 1.8.8, Rails version 2.1, to 2.2.2). See the Contents Page here. Method overloading is a common feature of several object-orientated languages. It allows the same name to be used for methods that perform the same, but accept different parameter types. Here is an example in Java: // Method overloading in Jav
RailsでUserモデルがあってそれがnameという属性を持っているとする. このとき例えば, User#nameの値を条件fooによって変えたいとき, class User < ActiveRecord::Base def name foo ? self[:name] : 'some special value' end end のようにnameメソッドを上書きしてやればよい. ちなみにself[:name]の[]はread_attributeのaliasで, 別にwrite_attributeもあるらしい(参考). ※ 上書きというよりは先に定義していると言った方が正確だと思う. というのもaround aliasを使って class User < ActiveRecord::Base alias :org_name :name def name foo ? org_name : '
In computer programming, monkey patching is a technique used to dynamically update the behavior of a piece of code at run-time. It is used to extend or modify the runtime code of dynamic languages such as Smalltalk, JavaScript, Objective-C, Ruby, Perl, Python, Groovy, and Lisp without altering the original source code. The term monkey patch seems to have come from an earlier term, guerrilla patch,
I have added a field to the sign-up form that is based on a different model, see How do I use nested attributes with the devise model for the gory details. This part is working fine. The problem now is when I save, it is failing in the create action of the registrations controller that is supplied by devise with an Activerecord::UnknownAttributeError on this field (company). I am assuming I need t
remove_method(*name) -> self[permalink][rdoc][edit] インスタンスメソッド name をモジュールから削除します。 Ruby 1.8.0 以降は複数のメソッド名を指定して一度に削除できます。 [PARAM] name: 0 個以上の String か Symbol を指定します。 [EXCEPTION] NameError: 指定したメソッドが定義されていない場合に発生します。 例 class C def foo end remove_method :foo remove_method :no_such_method # 例外 NameError が発生 end [SEE_ALSO] Module#undef_method
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く