diff options
author | Stan Lo <[email protected]> | 2024-02-13 13:33:33 +0000 |
---|---|---|
committer | git <[email protected]> | 2024-02-13 13:33:36 +0000 |
commit | ec26786b1a37350c0ff21666b028ec5e2aa6a318 () | |
tree | 74898ff938d7736be88fc25ded1d1fe7f3bd1896 /lib/irb/context.rb | |
parent | b5327647c2a49c36621631a06527837e99b009e5 (diff) |
[ruby/irb] Refactor eval_path and `SourceFinder::Source`
(https://.com/ruby/irb/pull/870) * Assign `@eval_path` through `irb_path=` method This simplifies the original caching logic for the `eval_path` method and makes it easier to understand. * Refactor SourceFinder::Source https://.com/ruby/irb/commit/c63e4c4035
-rw-r--r-- | lib/irb/context.rb | 42 |
1 files changed, 26 insertions, 16 deletions
@@ -77,7 +77,7 @@ module IRB else @irb_name = IRB.conf[:IRB_NAME]+"#"+IRB.JobManager.n_jobs.to_s end - @irb_path = "(" + @irb_name + ")" case input_method when nil @@ -121,11 +121,11 @@ module IRB when '-' @io = FileInputMethod.new($stdin) @irb_name = '-' - @irb_path = '-' when String @io = FileInputMethod.new(input_method) @irb_name = File.basename(input_method) - @irb_path = input_method else @io = input_method end @@ -246,9 +246,27 @@ module IRB # Can be either name from <code>IRB.conf[:IRB_NAME]</code>, or the number of # the current job set by JobManager, such as <code>irb#2</code> attr_accessor :irb_name - # Can be either the #irb_name surrounded by parenthesis, or the - # +input_method+ passed to Context.new - attr_accessor :irb_path # Whether multiline editor mode is enabled or not. # @@ -557,7 +575,7 @@ module IRB if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty? last_proc = proc do - result = @workspace.evaluate(line, eval_path, line_no) end IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) do |chain, item| _name, callback, arg = item @@ -568,20 +586,12 @@ module IRB end end.call else - result = @workspace.evaluate(line, eval_path, line_no) end set_last_value(result) end - private def eval_path - # We need to use differente path to distinguish source_location of method defined in the actual file and method defined in irb session. - if !defined?(@irb_path_existence) || @irb_path_existence[0] != irb_path - @irb_path_existence = [irb_path, File.exist?(irb_path)] - end - @irb_path_existence[1] ? "#{irb_path}(#{IRB.conf[:IRB_NAME]})" : irb_path - end - def inspect_last_value # :nodoc: @inspect_method.inspect_value(@last_value) end |