Skip to content

Instantly share code, notes, and snippets.

@ConradIrwin
Created September 11, 2011 06:27
Show Gist options
  • Select an option

  • Save ConradIrwin/1209250 to your computer and use it in GitHub Desktop.

Select an option

Save ConradIrwin/1209250 to your computer and use it in GitHub Desktop.
commit df812e1dfc4ea949f4a2c7467dd4924bf457fe72
Author: Conrad Irwin <conrad.irwin@gmail.com>
Date: Sat Sep 10 23:27:15 2011 -0700
Add a less hacky version for ree-1.8.7
diff --git a/lib/method_source/source_location.rb b/lib/method_source/source_location.rb
index 5010520..42dd99a 100644
--- a/lib/method_source/source_location.rb
+++ b/lib/method_source/source_location.rb
@@ -1,7 +1,10 @@
module MethodSource
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 +44,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 =~ /jruby/
# Return the source location for a Proc (Rubinius only)
# @return [Array] A two element array. First element is the
@@ -51,7 +56,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 +71,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 +82,7 @@ module MethodSource
def source_location
to_java.source_location(Thread.current.to_java.getContext())
end
+
else
@@ -118,5 +126,13 @@ module MethodSource
end
end
end
+
+ module ReeSourceLocation
+ # Ruby enterprise edition provides all the information that's
+ # needed, in a slightly different way.
+ def source_location
+ [__file__, __line__]
+ end
+ end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment