From 4e9b963b5a347aa9439703c7de99ade041cc3dc6 Mon Sep 17 00:00:00 2001 From: John Mair Date: Thu, 9 Jun 2011 05:30:15 +1200 Subject: added Proc#source_location support for ruby 1.8 --- lib/method_source/source_location.rb | 28 +++++++++++++++++++++------- lib/method_source/version.rb | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'lib/method_source') 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 -- cgit v1.2.1