ruby-changes:58863
From: manga_osyo <ko1@a...>
Date: Thu, 21 Nov 2019 00:48:59 +0900 (JST)
Subject: [ruby-changes:58863] 6723aa07e5 (master): Change argument `Proc` to `#call` defined object.
https://git.ruby-lang.org/ruby.git/commit/?id=6723aa07e5 From 6723aa07e591a13996b5af205c589200d44c5249 Mon Sep 17 00:00:00 2001 From: manga_osyo <manga.osyo@g...> Date: Wed, 20 Nov 2019 09:13:42 +0900 Subject: Change argument `Proc` to `#call` defined object. This is the same as the behavior of Readline. diff --git a/lib/reline.rb b/lib/reline.rb index feee94e..7352d1a 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -84,22 +84,22 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L84 end def completion_proc=(p) - raise ArgumentError unless p.is_a?(Proc) + raise ArgumentError unless p.respond_to?(:call) @completion_proc = p end def output_modifier_proc=(p) - raise ArgumentError unless p.is_a?(Proc) + raise ArgumentError unless p.respond_to?(:call) @output_modifier_proc = p end def prompt_proc=(p) - raise ArgumentError unless p.is_a?(Proc) + raise ArgumentError unless p.respond_to?(:call) @prompt_proc = p end def auto_indent_proc=(p) - raise ArgumentError unless p.is_a?(Proc) + raise ArgumentError unless p.respond_to?(:call) @auto_indent_proc = p end @@ -108,7 +108,7 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L108 end def dig_perfect_match_proc=(p) - raise ArgumentError unless p.is_a?(Proc) + raise ArgumentError unless p.respond_to?(:call) @dig_perfect_match_proc = p end diff --git a/test/reline/test_reline.rb b/test/reline/test_reline.rb index a0875d1..274f1aa 100644 --- a/test/reline/test_reline.rb +++ b/test/reline/test_reline.rb @@ -2,6 +2,10 @@ require_relative 'helper' https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L2 require "reline" class Reline::Test < Reline::TestCase + class DummyCallbackObject + def call; end + end + def setup end @@ -102,6 +106,10 @@ class Reline::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L106 assert_raise(ArgumentError) { Reline.completion_proc = 42 } assert_raise(ArgumentError) { Reline.completion_proc = "hoge" } + + dummy = DummyCallbackObject.new + Reline.completion_proc = dummy + assert_equal(dummy, Reline.completion_proc) end def test_output_modifier_proc @@ -117,6 +125,10 @@ class Reline::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L125 assert_raise(ArgumentError) { Reline.output_modifier_proc = 42 } assert_raise(ArgumentError) { Reline.output_modifier_proc = "hoge" } + + dummy = DummyCallbackObject.new + Reline.output_modifier_proc = dummy + assert_equal(dummy, Reline.output_modifier_proc) end def test_prompt_proc @@ -132,6 +144,10 @@ class Reline::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L144 assert_raise(ArgumentError) { Reline.prompt_proc = 42 } assert_raise(ArgumentError) { Reline.prompt_proc = "hoge" } + + dummy = DummyCallbackObject.new + Reline.prompt_proc = dummy + assert_equal(dummy, Reline.prompt_proc) end def test_auto_indent_proc @@ -147,6 +163,10 @@ class Reline::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L163 assert_raise(ArgumentError) { Reline.auto_indent_proc = 42 } assert_raise(ArgumentError) { Reline.auto_indent_proc = "hoge" } + + dummy = DummyCallbackObject.new + Reline.auto_indent_proc = dummy + assert_equal(dummy, Reline.auto_indent_proc) end def test_pre_input_hook @@ -174,6 +194,10 @@ class Reline::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L194 assert_raise(ArgumentError) { Reline.dig_perfect_match_proc = 42 } assert_raise(ArgumentError) { Reline.dig_perfect_match_proc = "hoge" } + + dummy = DummyCallbackObject.new + Reline.dig_perfect_match_proc = dummy + assert_equal(dummy, Reline.dig_perfect_match_proc) end def test_insert_text -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/