I think maybe you want this:
class Foo
def method_missing(sym, *args, &block)
puts "#{sym} was called with #{args} and returned #{block.call(args)}"
end
end
bar = Foo.new
bar.test(1,2,3) do |a|
a.map{|e| e + 2}
end
Execution result:
test was called with [1, 2, 3] and returned [3, 4, 5]
Updated: yield can be used as below.
puts "#{sym} was called with #{args} and returned #{yield(args) if block_given?}"