Skip to content

Commit 53ec648

Browse files
committed
maintain optional support for older rubies
1 parent 75eabad commit 53ec648

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/pry-rescue/source_location.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
21
if binding.respond_to?(:source_location)
32
raise 'source_location exists by default in Ruby 2.6 and greater, no need to required it manually'
43
else
54
class PryRescue
65
module SourceLocation
7-
DEPRECATION_TIME = Time.new(2021,4,1)
8-
9-
WithRuby2_5 = ->(b){ [b.eval("__FILE__"), b.eval("__LINE__")] }
6+
def self.call(b)
7+
[b.eval("__FILE__"), b.eval("__LINE__")]
8+
end
109
end
1110
end
1211

13-
Binding.define_method(:source_location, &PryRescue::SourceLocation::WithRuby2_5)
12+
Binding.define_method :source_location do
13+
PryRescue::SourceLocation.call(self)
14+
end
1415
end

spec/source_location_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
describe 'PryRescue::SourceLocation' do
22
if RUBY_VERSION < "2.6.0"
3+
require 'pry-rescue/source_location'
4+
35
subject { binding.source_location }
46

57
it 'matches [file, line]' do

0 commit comments

Comments
 (0)