From 6a1d06abc6c42e504a83dca4420c1d5ef39f09d2 Mon Sep 17 00:00:00 2001 From: Dimid Duchovny Date: Wed, 24 Jan 2018 23:09:06 +0200 Subject: doc: document block parameter of Msgthr#add Signed-off-by: Dimid Duchovny --- lib/msgthr.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/msgthr.rb b/lib/msgthr.rb index d88b32b..bf4b14e 100644 --- a/lib/msgthr.rb +++ b/lib/msgthr.rb @@ -148,7 +148,18 @@ class Msgthr # If +mid+ is a String, it is recommended to freeze the string before # calling this method to avoid wasting memory on hash keys. Likewise # is true for any String objects in +refs+. - def add(mid, refs, msg) + # + # Adding a message could link 2 messages in Msgthr, + # by making one message a child of the other. + # It's possible to have a callback called when a child is added + # by passing a block to this method. + # This block can access the child and parent messages. E.g. + # + # msgthr.add(0, nil, '0') + # msgthr.add(1, [0], '1') do |parent, child| + # puts "#{parent.mid} -> #{child.mid}" + # end + def add(mid, refs, msg) # :yields: parent, child @state == :init or raise StateError, "cannot add when already #@state" cur = @id_table[mid] ||= Msgthr::Container.new(mid) -- cgit v1.2.3-24-ge0c7