Ruby | Thread group() function
Thread#group() : group() is a Thread class method which returns the ThreadGroup which contains the given thread, or returns nil if thread is not a member of any group.
Syntax: Thread.group()
Parameter: Thread values
Return: the ThreadGroup which contains the given thread
nil – if thread is not a member of any group.
Example #1 :
# Ruby code for Thread.group() method # declaring Thread a = Thread.new { print "a"; Thread.stop; print "c" } # group formputs "Thread a group() form : #{a.group()}\n\n" |
Output :
Thread a group() form : #
Example #2 :
# Ruby code for Thread.group() method # declaring Thread a = Thread.new { puts "HI! I am learning to code"} # group formputs "Thread a group() form : #{a.group()}\n\n" |
Output :
Thread a group() form : #
Note :
The ThreadGroup object generated in the output depends on the system and pointer value. So, it may vary each time the code is run.


