== Sender http://rubygems.org/gems/sender == DESCRIPTION: Adds :__sender__ and :__caller__ to the built-in :__callee__ and :__method__ methods in Ruby 1.9.1, as well as providing object-oriented :backtrace supporting n-levels backward, and :backtrace_includes?, which allows contents of the backtrace to be queried. == SUMMARY: Adds object-oriented backtrace, which returns :object and :method for each stack frame, and which permits queries regarding backtrace contents. * __sender__ * __caller__ * backtrace * backtrace( frames_to_trace_backward ) * backtrace_includes?( Class ) * backtrace_includes?( class_instance ) * backtrace_includes?( :symbol ) * backtrace_includes?( Class, class_instance, :symbol, ... ) == INSTALL: * sudo gem install sender == EXAMPLE: require 'sender' require 'pp' class Test def initialize puts 'In method :initialize' puts 'Sender was: ' + __sender__.pretty_inspect.to_s puts 'Caller was: ' + __caller__.to_s end def test puts 'In :test' self.another_test end def another_test puts 'In method :another_test' test2 = Test2.new test2.and_another_test_in_another_object end def and_another_test_in_another_object puts 'In method :and_another_test_in_another_object' puts 'Sender was: ' + __sender__.pretty_inspect.to_s puts 'Caller was: ' + __caller__.to_s end end class Test2 < Test def initialize puts 'In method :initialize' super puts 'Sender was: ' + __sender__.pretty_inspect.to_s puts 'Caller was: ' + __caller__.to_s pp Kernel.backtrace end def and_another_test_in_another_object puts 'In method :and_another_test_in_another_object' super pp self puts 'Sender was: ' + __sender__.pretty_inspect.to_s puts 'Caller was: ' + __caller__.to_s pp Kernel.backtrace pp Kernel.backtrace( 2 ) puts 'These should be true:' pp Kernel.backtrace_includes?( :another_test ) pp Kernel.backtrace_includes?( Test ) pp Kernel.backtrace_includes?( $test ) pp Kernel.backtrace_includes?( :another_test, Test, $test ) puts 'These should be false:' pp Kernel.backtrace_includes?( :yet_another_test ) pp Kernel.backtrace_includes?( Test2 ) pp Kernel.backtrace_includes?( self ) pp Kernel.backtrace_includes?( :yet_another_test, Test2, self ) end end $test = Test.new $test.test puts 'Finished Test.' exit == EXAMPLE's OUTPUT: In method :initialize Sender was: main Caller was:
In :test In method :another_test In method :initialize In method :initialize Sender was: # Caller was: another_test Sender was: # Caller was: another_test [{:object=>#, :file=>"sender_test.rb", :line=>40, :method=>:initialize}, {:object=>Test2, :file=>nil, :line=>nil, :method=>:new}, {:object=>#, :file=>"sender_test.rb", :line=>20, :method=>:another_test}, {:object=>#, :file=>"sender_test.rb", :line=>15, :method=>:test}, {:object=>main, :file=>"sender_test.rb", :line=>66, :method=>:"
"}, {:object=>main, :file=>"
", :line=>0, :method=>:"
"}] In method :and_another_test_in_another_object In method :and_another_test_in_another_object This is the super method for :and_another_test_in_another_object Sender was: # Caller was: another_test # Sender was: # Caller was: another_test [{:object=>#, :file=>"sender_test.rb", :line=>49, :method=>:and_another_test_in_another_object}, {:object=>#, :file=>"sender_test.rb", :line=>21, :method=>:another_test}, {:object=>#, :file=>"sender_test.rb", :line=>15, :method=>:test}, {:object=>main, :file=>"sender_test.rb", :line=>66, :method=>:"
"}, {:object=>main, :file=>"
", :line=>0, :method=>:"
"}] [{:object=>#, :file=>"sender_test.rb", :line=>50, :method=>:and_another_test_in_another_object}, {:object=>#, :file=>"sender_test.rb", :line=>21, :method=>:another_test}] These should be true: true true true true These should be false: false false false false Finished Test. == LICENSE: (The MIT License) Copyright (c) 2010 Asher Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.