summaryrefslogtreecommitdiff
path: root/lib/pry/config.rb
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-05-04 18:09:57 +0300
committerKyrylo Silin <silin@kyrylo.org>2019-05-04 23:09:10 +0300
commit1d04fbd646a21dec380410bab2e8af610c5b6a24 (patch)
tree4ec0a3d50c4cc14a528f28089f75d3351af8ba36 /lib/pry/config.rb
parent8f6c792ae39d130fe132ef1d50ac9dd4a8469a6f (diff)
downloadpry-control-d-ruby-3-friendly.tar.gz
control_d_handler: don't mutate eval_string within the handlercontrol-d-ruby-3-friendly
This is a preparational step for #1824 (Enabling `# frozen_string_literal: true` in `~/.pryc` crashes most operations) Alternative to https://github.com/pry/pry/pull/2030 (config: delete the `control_d_handler` option) We had to jump a few hoops to change how the handler works. The problem is that mutation is the default expected behaviour. Therefore, we had to change its API. There's no need to pass `eval_string` because `pry_instance` already has it as an attribute. `config.control_d_handler` is a proxy proc, to preserve backwards compatibility with users of old signature (one known user is Pry Byebug). The handler will emit a warning if the old signature is used.
Diffstat (limited to 'lib/pry/config.rb')
-rw-r--r--lib/pry/config.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/pry/config.rb b/lib/pry/config.rb
index 55718200..2ed3542a 100644
--- a/lib/pry/config.rb
+++ b/lib/pry/config.rb
@@ -261,6 +261,33 @@ class Pry
@custom_attrs = @custom_attrs.dup
end
+ def control_d_handler=(value)
+ proxy_proc =
+ if value.arity == 2
+ Pry::Warning.warn(
+ "control_d_handler's arity of 2 parameters was deprecated. Now it " \
+ 'gets passed just 1 parameter (pry_instance). Please update your ' \
+ 'handler'
+ )
+ proc do |*args|
+ if args.size == 2
+ value.call(args.first, args[1])
+ else
+ value.call(args.first.eval_string, args.first)
+ end
+ end
+ else
+ proc do |*args|
+ if args.size == 2
+ value.call(args[1])
+ else
+ value.call(args.first)
+ end
+ end
+ end
+ @control_d_handler = proxy_proc
+ end
+
private
def lazy_readline