diff --git a/lib/pry-rescue/source_location.rb b/lib/pry-rescue/source_location.rb index 2f8f4dd..db4a5e5 100644 --- a/lib/pry-rescue/source_location.rb +++ b/lib/pry-rescue/source_location.rb @@ -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 diff --git a/spec/source_location_spec.rb b/spec/source_location_spec.rb index 48a2b93..497dbcf 100644 --- a/spec/source_location_spec.rb +++ b/spec/source_location_spec.rb @@ -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