1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Merge pull request #1904 from k0kubun/binding-source-location

Fix Ruby 2.6 warning for Binding#source_location
This commit is contained in:
Yuichiro Kaneko 2018-12-11 20:46:08 +09:00 committed by GitHub
commit 69f7d9d185
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 9 deletions

View file

@ -3,8 +3,12 @@ class Pry
module FileAndLineLocator module FileAndLineLocator
class << self class << self
def from_binding(target) def from_binding(target)
if target.respond_to?(:source_location)
target.source_location
else
[target.eval("__FILE__"), target.eval("__LINE__")] [target.eval("__FILE__"), target.eval("__LINE__")]
end end
end
def from_code_object(code_object, filename_argument) def from_code_object(code_object, filename_argument)
if File.exist?(code_object.source_file.to_s) if File.exist?(code_object.source_file.to_s)

View file

@ -86,7 +86,13 @@ class Pry
# The file to play from when no code object is specified. # The file to play from when no code object is specified.
# e.g `play --lines 4..10` # e.g `play --lines 4..10`
def default_file def default_file
target.eval("__FILE__") && File.expand_path(target.eval("__FILE__")) file =
if target.respond_to?(:source_location)
target.source_location.first
else
target.eval("__FILE__")
end
file && File.expand_path(file)
end end
def file_content def file_content

View file

@ -27,7 +27,13 @@ class Pry
private private
def current_file def current_file
File.expand_path target.eval("__FILE__") file =
if target.respond_to?(:source_location)
target.source_location.first
else
target.eval("__FILE__")
end
File.expand_path file
end end
def reload_current_file def reload_current_file

View file

@ -37,8 +37,13 @@ class Pry
BANNER BANNER
def setup def setup
if target.respond_to?(:source_location)
file, @line = target.source_location
@file = expand_path(file)
else
@file = expand_path(target.eval('__FILE__')) @file = expand_path(target.eval('__FILE__'))
@line = target.eval('__LINE__') @line = target.eval('__LINE__')
end
@method = Pry::Method.from_binding(target) @method = Pry::Method.from_binding(target)
end end

View file

@ -25,7 +25,11 @@ class Pry
# @return [Boolean] # @return [Boolean]
def normal_method?(method, b) def normal_method?(method, b)
if method && method.source_file && method.source_range if method && method.source_file && method.source_range
if b.respond_to?(:source_location)
binding_file, binding_line = b.source_location
else
binding_file, binding_line = b.eval('__FILE__'), b.eval('__LINE__') binding_file, binding_line = b.eval('__FILE__'), b.eval('__LINE__')
end
(File.expand_path(method.source_file) == File.expand_path(binding_file)) && (File.expand_path(method.source_file) == File.expand_path(binding_file)) &&
method.source_range.include?(binding_line) method.source_range.include?(binding_line)
end end
@ -77,15 +81,31 @@ class Pry
end end
def target_file def target_file
pry_file? ? target.eval('__FILE__') : File.expand_path(target.eval('__FILE__')) file =
if target.respond_to?(:source_location)
target.source_location.first
else
target.eval('__FILE__')
end
pry_file? ? file : File.expand_path(file)
end end
def target_line def target_line
if target.respond_to?(:source_location)
target.source_location.last
else
target.eval('__LINE__') target.eval('__LINE__')
end end
end
def pry_file? def pry_file?
Pry.eval_path == target.eval('__FILE__') file =
if target.respond_to?(:source_location)
target.source_location.first
else
target.eval('__FILE__')
end
Pry.eval_path == file
end end
# it's possible in some cases that the method we find by this approach is a sub-method of # it's possible in some cases that the method we find by this approach is a sub-method of