Skip to content

Commit

Permalink
maintain optional support for older rubies
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonewall committed Aug 20, 2022
1 parent 75eabad commit 53ec648
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/pry-rescue/source_location.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

if binding.respond_to?(:source_location)
raise 'source_location exists by default in Ruby 2.6 and greater, no need to required it manually'
else
class PryRescue
module SourceLocation
DEPRECATION_TIME = Time.new(2021,4,1)

WithRuby2_5 = ->(b){ [b.eval("__FILE__"), b.eval("__LINE__")] }
def self.call(b)
[b.eval("__FILE__"), b.eval("__LINE__")]
end
end
end

Binding.define_method(:source_location, &PryRescue::SourceLocation::WithRuby2_5)
Binding.define_method :source_location do
PryRescue::SourceLocation.call(self)
end
end
2 changes: 2 additions & 0 deletions spec/source_location_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
describe 'PryRescue::SourceLocation' do
if RUBY_VERSION < "2.6.0"
require 'pry-rescue/source_location'

subject { binding.source_location }

it 'matches [file, line]' do
Expand Down

0 comments on commit 53ec648

Please sign in to comment.