This is so simple, but yet so elegant (in my humble opinion).
def compose_procs(procs)
lambda do |input|
procs.inject(input) { |x, f| f[x] }
end
end
filters = [
lambda { |x| x.gsub("World", "Planet Earth") },
lambda { |x| RedCloth.new(x).to_html }
]
compose_procs(filters)["Hello *World*!"]
# => "<p>Hello <strong>Planet Earth</strong>!</p>"