Multi-method
[ruby-talk:187149]
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/187149にて、
[ruby-dev:28533] Multi Methods
URABE Shyouhei proposed a rough idea for multi methods (in lisp as
generic function) for ruby
The syntax is
def foo( SPEC val)
SPEC is any object which respond to "===".
This allow multiple dispatch class based or like eql? specializer in
lisp.But if ther is not a matching SPEC beetween all methods it is still
called, for duck typing.
Matz said he agrees and this can be committed to 1.9 if it is
fast implementation.
とか書いてあるのだけど、ひょっとしてこれってエイプリルフールのネタ?[ruby-dev:28533]なんて今のところ存在してないし…。
簡単に上のやつを説明すると、今まで
def foo(str) return nil unless str === String ... end
などとかいていたやつが、
def foo(String str) ... end
と書けたりするようになるようです。
個人的には取る引数の型によって挙動の異なるメソッドもcase文で分岐ではなく定義のところで見られるのでこれが採用されると少しうれしいかも。