diff options
author | John Mair <jrmair@gmail.com> | 2011-10-02 03:33:06 -0700 |
---|---|---|
committer | John Mair <jrmair@gmail.com> | 2011-10-02 03:33:06 -0700 |
commit | 0a4f122cbee8ee553342835e4e720a2cc8898f33 (patch) | |
tree | 74c97f783963fcf650d4febe69dc254d2fde4a44 | |
parent | 1bc628ec8eb648fd3e3266b11cbab3a4f36089e9 (diff) | |
parent | ca9ac8ee73a1fc19f7f83c689c7ec975cdccaee9 (diff) | |
download | method_source-0a4f122cbee8ee553342835e4e720a2cc8898f33.tar.gz |
Merge pull request #9 from ConradIrwin/master
Use Ruby enterprise edition's __file__ and __line__ methods.
-rw-r--r-- | lib/method_source/source_location.rb | 24 |
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..faa96c7 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.method_defined? :__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.method_defined? :__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.method_defined? :__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 |