動的alias
http://yowaken.dip.jp/tdiary/20080720.html#p02
http://jarp.does.notwork.org/diary/200807b.html#200807201
関連して。キャッシュしてるとはいえ毎回method_missingを呼ぶよりは…
@@ -2,6 +2,7 @@ @@golf_hash = {} def method_missing m, *a, &b t = @@golf_hash[ [m,self.class] ] ||= matching_methods(m)[0] + self.class.class_eval "alias #{m} #{t}" if t t ? __send__(t, *a, &b) : super end @@ -14,7 +15,7 @@ def self.const_missing c t = @@golf_hash[ [c,self.class] ] ||= matching_methods(c,constants)[0] - t and return const_get(t) + t and return const_set(c, const_get(t)) raise NameError, "uninitialized constant #{c}", caller(1) end
こうするほうがいいような。@@golf_hashも省ける。