From 88d94d470dd5b6fba97e448d5f8205df2d6b448b Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Sat, 10 Sep 2011 23:27:15 -0700 Subject: Add a less hacky version for ree-1.8.7 --- lib/method_source/source_location.rb | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/method_source/source_location.rb b/lib/method_source/source_location.rb index 5010520..6cd5e94 100644 --- a/lib/method_source/source_location.rb +++ b/lib/method_source/source_location.rb @@ -1,7 +1,18 @@ module MethodSource + module ReeSourceLocation + # Ruby enterprise edition provides all the information that's + # needed, in a slightly different way. + def source_location + [__file__, __line__] rescue nil + end + end + module SourceLocation module MethodExtensions - if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ + if Proc.new {}.respond_to? :__file__ + include ReeSourceLocation + + elsif defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ require 'java' # JRuby version source_location hack @@ -41,8 +52,10 @@ module MethodSource end module ProcExtensions + if Proc.new {}.respond_to? :__file__ + include ReeSourceLocation - if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/ + elsif 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 @@ -51,7 +64,6 @@ module MethodSource def source_location [block.file.to_s, block.line] end - else # Return the source location for a Proc (in implementations @@ -67,7 +79,10 @@ module MethodSource end module UnboundMethodExtensions - if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ + if Proc.new {}.respond_to? :__file__ + include ReeSourceLocation + + elsif defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ require 'java' # JRuby version source_location hack @@ -75,6 +90,7 @@ module MethodSource def source_location to_java.source_location(Thread.current.to_java.getContext()) end + else -- cgit v1.2.1