diff options
author | John Mair <jrmair@gmail.com> | 2011-02-28 04:04:48 +1300 |
---|---|---|
committer | John Mair <jrmair@gmail.com> | 2011-02-28 04:04:48 +1300 |
commit | 0a4dec32fb31ddfc9c5f658c7eb9789580cc6741 (patch) | |
tree | 9ff06405bda9da045b42fe30ffb5dae5724a5aff | |
parent | 52ef85631d136a4ff31c0f4c2587b19db3daf512 (diff) | |
download | method_source-0a4dec32fb31ddfc9c5f658c7eb9789580cc6741.tar.gz |
version 0.3.2, added more tests and improved some code
-rw-r--r-- | lib/method_source/source_location.rb | 6 | ||||
-rw-r--r-- | lib/method_source/version.rb | 2 | ||||
-rw-r--r-- | test/test.rb | 15 | ||||
-rw-r--r-- | test/test_helper.rb | 7 |
4 files changed, 28 insertions, 2 deletions
diff --git a/lib/method_source/source_location.rb b/lib/method_source/source_location.rb index 1878b18..f1929e1 100644 --- a/lib/method_source/source_location.rb +++ b/lib/method_source/source_location.rb @@ -1,6 +1,7 @@ module MethodSource module SourceLocation module MethodExtensions + def trace_func(event, file, line, id, binding, classname) return unless event == 'call' set_trace_func nil @@ -8,6 +9,8 @@ module MethodSource @file, @line = file, line raise :found end + + private :trace_func # Return the source location of a method for Ruby 1.8. # @return [Array] A two element array. First element is the @@ -37,7 +40,8 @@ module MethodSource when Class owner when Module - Class.new.tap { |v| v.send(:include, owner) } + method_owner = owner + Class.new { include(method_owner) } end begin diff --git a/lib/method_source/version.rb b/lib/method_source/version.rb index 6a830a9..73cdbab 100644 --- a/lib/method_source/version.rb +++ b/lib/method_source/version.rb @@ -1,3 +1,3 @@ module MethodSource - VERSION = "0.3.0" + VERSION = "0.3.2" end diff --git a/test/test.rb b/test/test.rb index 8b84538..2a8eee2 100644 --- a/test/test.rb +++ b/test/test.rb @@ -7,6 +7,8 @@ require "#{direc}/test_helper" describe MethodSource do before do + @hello_module_source = " def hello; :hello_module; end\n" + @hello_singleton_source = "def $o.hello; :hello_singleton; end\n" @hello_source = "def hello; :hello; end\n" @hello_comment = "# A comment for hello\n# It spans two lines and is indented by 2 spaces\n" @lambda_comment = "# This is a comment for MyLambda\n" @@ -24,6 +26,19 @@ describe MethodSource do it 'should return source for method' do method(:hello).source.should == @hello_source end + + it 'should return source for a method defined in a module' do + M.instance_method(:hello).source.should == @hello_module_source + end + + it 'should return source for a singleton method as an instance method' do + class << $o; self; end.instance_method(:hello).source.should == @hello_singleton_source + end + + it 'should return source for a singleton method' do + $o.method(:hello).source.should == @hello_singleton_source + end + it 'should return a comment for method' do method(:hello).comment.should == @hello_comment diff --git a/test/test_helper.rb b/test/test_helper.rb index bb28e29..26d108b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,6 +4,13 @@ class String end end +module M + def hello; :hello_module; end +end + +$o = Object.new +def $o.hello; :hello_singleton; end + # A comment for hello # It spans two lines and is indented by 2 spaces |