Pythonのdecorator は格好いいよね。Rubyでこんな感じのものを作れないかと何回か考えたものの、上手いAPIを思いつかずにいた。 このたび、 technohippyさんの挑戦 に刺激されて書いてみた。 decorator.rb 仕様としてはPythonに合わせて、呼び出し可能オブジェクトを返す関数としてdecoratorを作成する。そして、declareというメソッドにdecoratorを渡すと、ブロック内で定義されたメソッドはdecoratorで修飾される。 例 class Module def type(name, types) before(name) do |name, args| args.zip(types).each_with_index do |(arg, type), i| raise TypeError, "#{i}th argument #{arg} s