[前][次][番号順一覧][スレッド一覧]

ruby-changes:65734

From: Cody <ko1@a...>
Date: Sat, 3 Apr 2021 00:49:41 +0900 (JST)
Subject: [ruby-changes:65734] 3cab8c087f (master): [ruby/irb] process multi-line pastes as a single entity

https://git.ruby-lang.org/ruby.git/commit/?id=3cab8c087f

From 3cab8c087f0093f2d4669c283be30d01f8e17d5d Mon Sep 17 00:00:00 2001
From: Cody Cutrer <cody@i...>
Date: Tue, 16 Mar 2021 15:45:45 -0600
Subject: [ruby/irb] process multi-line pastes as a single entity

this allows pasting leading-dot chained methods correctly:

```ruby
class A
  def a; self; end
  def b; true; end
end

a = A.new

a
 .a
 .b
```

will properly return `true` instead of erroring on the `.a` line:

```
irb(main):001:1*     class A
irb(main):002:1*       def a; self; end
irb(main):003:0>     end
irb(main):004:0*
irb(main):005:0>     a = A.new
irb(main):006:0*
irb(main):007:0>     a
irb(main):008:0>      .a
irb(main):009:0>      .a
=> #<A:0x00007f984211fbe8>
```

https://github.com/ruby/irb/commit/45aeb52575
---
 lib/irb/input-method.rb | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index 1854567..df73cee 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -316,7 +316,13 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/input-method.rb#L316
       Reline.output = @stdout
       Reline.prompt_proc = @prompt_proc
       Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc
-      if l = readmultiline(@prompt, false, &@check_termination_proc)
+
+      l = readmultiline(@prompt, false) do |line|
+        next false if Reline::IOGate.in_pasting?
+        @check_termination_proc.call(line)
+      end
+
+      if l
         HISTORY.push(l) if !l.empty?
         @line[@line_no += 1] = l + "\n"
       else
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]