h1. message recorder h2. → 'message-recorder' h2. What Message::Recorder is a tool to record messages send to Ruby objects. h2. Installing
sudo gem install message-recorder
h2. The basics This snippet will first record a downcase message and after that it will replay the recorded messages on some objects.
recorder = Message::Recorder.new
recorder.record.downcase
recorder.send_to("HELLO") # => ["hello"]
recorder.send_to("WORLD") # => ["world"]
This is an example of branching. the with_results method accepts a block which is used to define multiple message chains at once.
recorder = Message::Recorder.new
recorder.record.downcase.with_results do
  intern
  capitalize
end

recorder.send_to("HELLO") # => [:hello, "Hello"]
h2. Demonstration of usage This is a more complex example with nested branches.
recorder = Message::Recorder.new
recorder.record.compact.with_result do
  collect { |s| s.intern }
  collect { |s| s.capitalize }.with_results do
    collect { |s| s.concat " world" }
    collect { |s| s.concat " simon" }
  end.with_results do
    collect { |s| s.concat "!" }
    collect { |s| s.concat "?" }
  end
end

results = recorder.send_to([nil, "hello", nil, "bye", nil])
results == [ # the result is ...
  [:hello, :bye],
  ["Hello world!", "Bye world!"],
  ["Hello simon!", "Bye simon!"],
  ["Hello world?", "Bye world?"],
  ["Hello simon?", "Bye simon?"]
]
h2. License This code is free to use under the terms of the MIT license. h2. Contact Comments are welcome. Send an email to "Simon Menke":mailto:simon@5xm.org