about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorDimid Duchovny <dimidd@gmail.com>2018-01-24 23:09:06 +0200
committerDimid Duchovny <dimidd@gmail.com>2018-01-24 23:09:06 +0200
commit6a1d06abc6c42e504a83dca4420c1d5ef39f09d2 (patch)
tree34a5cda26416cd0be617918b179a106baed143f0
parentaca7c9a93eb77c32ef112c193169a4618d425432 (diff)
downloadmsgthr-6a1d06abc6c42e504a83dca4420c1d5ef39f09d2.tar.gz
Signed-off-by: Dimid Duchovny <dimidd@gmail.com>
-rw-r--r--lib/msgthr.rb13
1 files changed, 12 insertions, 1 deletions
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)