summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConrad Irwin <conrad.irwin@gmail.com>2011-09-10 23:27:15 -0700
committerConrad Irwin <conrad.irwin@gmail.com>2011-10-01 18:36:10 -0700
commit88d94d470dd5b6fba97e448d5f8205df2d6b448b (patch)
tree8f74763d5e8f5e13656547e7bd9b4fb57e089400
parent1bc628ec8eb648fd3e3266b11cbab3a4f36089e9 (diff)
downloadmethod_source-88d94d470dd5b6fba97e448d5f8205df2d6b448b.tar.gz
Add a less hacky version for ree-1.8.7
-rw-r--r--lib/method_source/source_location.rb24
1 files changed, 20 insertions, 4 deletions
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