ユーザーの便宜とよりクリーンなコードのために、次のように使用できるクラスを作成したいと思います。
Encoder::Theora.encode do
infile = "path/to/infile"
outfile = "path/to/outfile"
passes = 2
# ... more params
end
ここでの課題は、そのパラメーターをエンコードメソッドで使用できるようにすることです。
module Encoder
class Theora
def self.encode(&proc)
proc.call
# do some fancy encoding stuff here
# using the parameters from the proc
end
end
end
このアプローチは機能しません。Procが呼び出されると、変数はTheoraクラスのコンテキストで評価されません。通常、method_missingを使用して、すべてのパラメーターをクラスTheoraのクラス変数に入れたいのですが、エントリの正しい方法が見つかりません。
誰かが私を正しい方向に向けることができますか?