ruby-changes:64288
From: aycabta <ko1@a...>
Date: Sat, 19 Dec 2020 02:24:07 +0900 (JST)
Subject: [ruby-changes:64288] 671f2762fb (master): [ruby/reline] Add Enumerable to KillRing for debugging
https://git.ruby-lang.org/ruby.git/commit/?id=671f2762fb From 671f2762fb8a4832d2c17322ee600f53c91f76f5 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Fri, 18 Dec 2020 22:25:09 +0900 Subject: [ruby/reline] Add Enumerable to KillRing for debugging https://github.com/ruby/reline/commit/d208874152 diff --git a/lib/reline/kill_ring.rb b/lib/reline/kill_ring.rb index 842fd04..bb3684b 100644 --- a/lib/reline/kill_ring.rb +++ b/lib/reline/kill_ring.rb @@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/lib/reline/kill_ring.rb#L1 class Reline::KillRing + include Enumerable + module State FRESH = :fresh CONTINUED = :continued @@ -110,4 +112,14 @@ class Reline::KillRing https://github.com/ruby/ruby/blob/trunk/lib/reline/kill_ring.rb#L112 nil end end + + def each + start = head = @ring.head + loop do + break if head.nil? + yield head.str + head = head.backward + break if head == start + end + end end diff --git a/test/reline/test_kill_ring.rb b/test/reline/test_kill_ring.rb index 8bebfe2..9f6e0c3 100644 --- a/test/reline/test_kill_ring.rb +++ b/test/reline/test_kill_ring.rb @@ -253,4 +253,16 @@ class Reline::KillRing::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_kill_ring.rb#L253 assert_equal(['AB', 'abcde'], @kill_ring.yank_pop) assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state)) end + + def test_enumerable + @kill_ring.append('a') + @kill_ring.process + @kill_ring.process + @kill_ring.append('b') + @kill_ring.process + @kill_ring.process + @kill_ring.append('c') + @kill_ring.process + assert_equal(%w{c b a}, @kill_ring.to_a) + end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/