Rubyで、クラスの内部から基底クラスのメソッドを呼び出す場合は、
superを使えば良いのですが、
どうしても外部から基底クラスのメソッドを呼び出したい場合には、
以下のようにすれば実現出来ます。

ruby>>

class Foo; def foo; puts "foo#{self}"; end end
=> nil

class Bar < Foo; def foo; puts "bar#{self}"; end end
=> nil

Bar.new.foo
bar#Bar:0x25c2d60
<<--

このように、通常は基底クラスのメソッドを直接呼び出す事は出来ませんが、

ruby>>

Foo.instance_method(:foo).bind(Bar.new).call
foo#Bar:0x25b7f00
<<--

一度UnboundMethodにしてから、もう一度バインドする事で、
基底クラスのメソッドを呼び出す事が出来ます。

posted by genki genki on Sun 25 Jan 2009 at 06:38 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
https://landminder.com/author/sharonhindman https://landminder.com/author/sharonhindman: Работает стабильно даже на больших объемах данных. 04/23 05:59
https://mimrent.com/author/laylazercho023/ https://mimrent.com/author/laylazercho023/: Good blog. I really liked this. Many thanks for ... 04/23 02:56
https://xn--mgmrket6-px0d.com https://xn--mgmrket6-px0d.com: Как отличить настоящее зеркало MEGA от подделки в ... 04/22 23:19
https://xn--mgmarkt5-9db.com https://xn--mgmarkt5-9db.com: Как проверить безопасность MEGA: аудит аккаунта в ... 04/22 23:08
https://uae.buyallasia.com/author-profile/lilianahornick/ https://uae.buyallasia.com/author-profile/lilianahornick/: Пользуюсь IndexChecker уже месяц, полет нормальный... 04/22 20:07
https://mp3diary.com/sheliacunningh https://mp3diary.com/sheliacunningh: Помогло быстро выявить ссылки, которые не попали ... 04/22 19:54
https://healthjobslounge.com/employer/tenchat/ https://healthjobslounge.com/employer/tenchat/: Отчеты в CSV формате — это то, чего мне не хватал... 04/22 19:53
https://overseas-realestate.com/author/rexmaccarthy67/ https://overseas-realestate.com/author/rexmaccarthy67/: Реально экономит время при аудите сайта. 04/22 19:47