Sha256: ca7f6d77ae9ec4d2437f62373178cdace6e11c60dc8d95d231a526152700baad
Contents?: true
Size: 1.57 KB
Versions: 5
Compression:
Stored size: 1.57 KB
Contents
= message recorder == What <tt>Message::Recorder</tt> is a tool to record messages send to Ruby objects. == Installing sudo gem install message-recorder == The basics This snippet will first record a <tt>downcase</tt> 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 <tt>with_results</tt> 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"] == 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?"] ] == License This code is free to use under the terms of the MIT license. == Contact Comments are welcome. Send an email to Simon Menke mailto:simon@5xm.org
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
message-recorder-1.0.1 | README.txt |
message-recorder-1.0.2 | README.txt |
message-recorder-1.0.3 | README.txt |
message-recorder-1.0.4 | README.txt |
message-recorder-1.0.0 | README.txt |