summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mair <jrmair@gmail.com>2011-06-09 05:30:15 +1200
committerJohn Mair <jrmair@gmail.com>2011-06-09 05:43:20 +1200
commit4e9b963b5a347aa9439703c7de99ade041cc3dc6 (patch)
treeb71a902b4267b8f29811e556345ea23a18fc9135
parent828a56c9feab63bb05da0c4c265d30588e7bec82 (diff)
downloadmethod_source-4e9b963b5a347aa9439703c7de99ade041cc3dc6.tar.gz
added Proc#source_location support for ruby 1.8
-rw-r--r--lib/method_source.rb5
-rw-r--r--lib/method_source/source_location.rb28
-rw-r--r--lib/method_source/version.rb2
-rw-r--r--test/test.rb6
4 files changed, 26 insertions, 15 deletions
diff --git a/lib/method_source.rb b/lib/method_source.rb
index 33eeb1f..daaa135 100644
--- a/lib/method_source.rb
+++ b/lib/method_source.rb
@@ -170,10 +170,7 @@ class UnboundMethod
end
class Proc
+ include MethodSource::SourceLocation::ProcExtensions
include MethodSource::MethodExtensions
-
- if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
- include MethodSource::SourceLocation::ProcExtensions
- end
end
diff --git a/lib/method_source/source_location.rb b/lib/method_source/source_location.rb
index 4e078f7..337e997 100644
--- a/lib/method_source/source_location.rb
+++ b/lib/method_source/source_location.rb
@@ -29,15 +29,29 @@ module MethodSource
end
end
- # Rubinius only
module ProcExtensions
- # Return the source location for a Proc (Rubinius only)
- # @return [Array] A two element array. First element is the
- # file, second element is the line in the file where the
- # proc definition is found.
- def source_location
- [block.file.to_s, block.line]
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
+
+ # Return the source location for a Proc (Rubinius only)
+ # @return [Array] A two element array. First element is the
+ # file, second element is the line in the file where the
+ # proc definition is found.
+ def source_location
+ [block.file.to_s, block.line]
+ end
+
+ else
+
+ # Return the source location for a Proc (in implementations
+ # without Proc#source_location)
+ # @return [Array] A two element array. First element is the
+ # file, second element is the line in the file where the
+ # proc definition is found.
+ def source_location
+ self.to_s =~ /@(.*):(\d+)/
+ [$1, $2.to_i]
+ end
end
end
diff --git a/lib/method_source/version.rb b/lib/method_source/version.rb
index 805f2fc..ddc524b 100644
--- a/lib/method_source/version.rb
+++ b/lib/method_source/version.rb
@@ -1,3 +1,3 @@
module MethodSource
- VERSION = "0.5.0"
+ VERSION = "0.6.0"
end
diff --git a/test/test.rb b/test/test.rb
index 8fb33b1..fd1113f 100644
--- a/test/test.rb
+++ b/test/test.rb
@@ -10,7 +10,7 @@ describe MethodSource do
describe "emitted warnings" do
it 'should emit no warnings' do
- Open4.popen4 'ruby -I lib -r"method_source" -W -e "exit"' do |pid,stdin,stdout,stderr|
+ Open4.popen4 'ruby -I lib -rubygems -r"method_source" -W -e "exit"' do |pid,stdin,stdout,stderr|
stderr.read.empty?.should == true
end
end
@@ -80,7 +80,7 @@ describe MethodSource do
end
end
- if RUBY_VERSION =~ /1.9/ || is_rbx?
+ # if RUBY_VERSION =~ /1.9/ || is_rbx?
describe "Lambdas and Procs" do
it 'should return source for proc' do
MyProc.source.should == @proc_source
@@ -98,7 +98,7 @@ describe MethodSource do
MyLambda.comment.should == @lambda_comment
end
end
- end
+ # end
describe "Comment tests" do
before do
@comment1 = "# a\n# b\n"