When one is programming one often want to send a procedure as argument of the method. For instance, when one is writing something to process the signals. It may be convenient if the procedures can be specifed as arguments for each arrivals of signals.
To specify the process for signals, use the `trap' method in ruby.
ruby> trap "SIGUSR1", 'print "foobar\n"' nil ruby> Process.kill "SIGUSR1", $$ foobar 1
There is specified the process for arrival of the signal `SIGUSR1' by the string here. It is the way owing to ruby's nature of being an interpreter. Though, through no strings, one can let the procedure affect an object directly.
ruby> trap "SIGUSR1", proc{print "foobar\n"} nil ruby> Process.kill "SIGUSR1", $$ foobar 1
The `proc' method generates a `procedure object' from the region within the braces {}. To execute the procedure object, one can use the `call' method.
ruby> proc = proc{print "foo\n"} #<Proc:0x83c90> ruby> proc.call foo nil
As the handler or the call-back, the uses of the procedure objects are similar to the function pointers in C. We are free from defining any functions or methods for these purposes (also free from naming), it may be convenient. ない.