📜  红宝石 |线程 add_trace_func函数

📅  最后修改于: 2022-05-13 01:55:20.375000             🧑  作者: Mango

红宝石 |线程 add_trace_func函数

Thread#add_trace_func() : add_trace_func()是一个 Thread 类方法,它添加进程作为跟踪的处理程序。

示例 #1:

# Ruby code for Thread.add_trace_func() method
  
# declaring Thread 
a = Thread.new { print "a"; Thread.stop; print "c" }
  
prc = lambda {puts 'Hello'}  
  
# add_trace_func form
puts "Thread a add_trace_func() form : #{a.add_trace_func(prc)}\n\n"

输出 :

Thread a add_trace_func() form : #

示例 #2:

# Ruby code for Thread.add_trace_func() method
  
# declaring Thread 
a = Thread.new { puts "HI! I am learning to code"}
  
prc = lambda {puts 'Hello'}  
  
# add_trace_func form
puts "Thread a add_trace_func() form : #{a.add_trace_func(prc)}\n\n"

输出 :

Thread a add_trace_func() form : #