proc

proc { ... }で手続きオブジェクト(Procオブジェクト)を作ると、ブロック付きのメソッド呼び出しで手続きを別途渡すことができます。

class Array
    def my_each
        for e in self
            yield(e)
        end
    end
end

def print_them(a)
    myproc = proc {|k|
        print "#{k} (#{k.class}), "
    }
    a.my_each(&myproc)
    print "\n"
end

print_them([100, 200, 300])
# => 100 (Fixnum), 200 (Fixnum), 300 (Fixnum),

print_them([123, 3.14, "Hello", 1234567890])
# => 123 (Fixnum), 3.14 (Float), Hello (String), 1234567890 (Bignum),