diff options
author | Stan Lo <[email protected]> | 2024-04-12 20:00:58 +0800 |
---|---|---|
committer | git <[email protected]> | 2024-04-12 12:01:03 +0000 |
commit | f1d9e895b92953add4b12f477c27852cc3d0955b () | |
tree | d8bc1f904208e0206966c949c0fa6f290422d99b /lib/irb/context.rb | |
parent | 7b8b936f4a1cd9a629c0465c287fd0ed40519ebe (diff) |
[ruby/irb] Pass statements to Context#evaluate
(https://.com/ruby/irb/pull/920) This has a few benefits: - We can keep hiding the evaluation logic inside the Context level, which has always been the convention until #824 was merged recently. - Although not an official API, gems like `debug` and `mission_control-jobs` `Context#evaluate` to wrap their own logic around it. This implicit contract was broken after #824, and this change restores it. In addition to the refactor, I also converted some context-level evaluation tests into integration tests, which are more robust and easier to maintain. https://.com/ruby/irb/commit/b32aee4068
-rw-r--r-- | lib/irb/context.rb | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -585,31 +585,44 @@ module IRB @inspect_mode end - def evaluate(line, line_no) # :nodoc: @line_no = line_no result = nil if IRB.conf[:MEASURE] && IRB.conf[:MEASURE_CALLBACKS].empty? IRB.set_measure_callback end 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 proc do - callback.(self, line, line_no, arg) do chain.call end end end.call else - result = workspace.evaluate(line, @eval_path, line_no) end - - set_last_value(result) end def inspect_last_value # :nodoc: |