これが私がやりたいことです:
class Directory
def doSomething
end
def subs
# => an array of Directory objects
end
def recursively (method)
self.subs.each do |sub|
sub.method
sub.recursively method
end
end
end
cd = Directory.new
cd.recursively 'doSomething'
# ...and extra points if theres a way to:
cd.recursively.doSomething
これを理解するために、ディレクトリ内のファイルとそのすべてのサブディレクトリに変更を加える小さなスクリプトを作成しています。これらのサブディレクトリは、拡張Directory
オブジェクトになります。
では、メソッドを別のメソッドのパラメーターとして渡す方法はありますか?