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

ruby-changes:45460

From: nobu <ko1@a...>
Date: Sat, 4 Feb 2017 19:48:21 +0900 (JST)
Subject: [ruby-changes:45460] nobu:r57533 (trunk): pty/shl.rb: update [ci skip]

nobu	2017-02-04 19:48:15 +0900 (Sat, 04 Feb 2017)

  New Revision: 57533

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57533

  Log:
    pty/shl.rb: update [ci skip]
    
    * sample/pty/shl.rb: do not manage array length separately.
      [ruby-dev:49974] [Bug #13191]

  Modified files:
    trunk/sample/pty/shl.rb
Index: sample/pty/shl.rb
===================================================================
--- sample/pty/shl.rb	(revision 57532)
+++ sample/pty/shl.rb	(revision 57533)
@@ -14,7 +14,6 @@ require 'pty' https://github.com/ruby/ruby/blob/trunk/sample/pty/shl.rb#L14
 require 'io/console'
 
 $shells = []
-$n_shells = 0
 
 $r_pty = nil
 $w_pty = nil
@@ -64,17 +63,15 @@ while true https://github.com/ruby/ruby/blob/trunk/sample/pty/shl.rb#L63
   STDOUT.flush
   case gets
   when /^c/i
-    $shells[$n_shells] = PTY.spawn("/bin/csh")
-    $r_pty,$w_pty = $shells[$n_shells]
-    $n_shells += 1
+    $shells << PTY.spawn("/bin/csh")
+    $r_pty,$w_pty = $shells[-1]
     $reader.run
     if writer == 'Exit'
-      $n_shells -= 1
-      $shells[$n_shells] = nil
+      $shells.pop
     end
   when /^p/i
-    for i in 0..$n_shells
-      unless $shells[i].nil?
+    $shells.each_with_index do |s, i|
+      if s
         print i,"\n"
       end
     end
@@ -87,6 +84,7 @@ while true https://github.com/ruby/ruby/blob/trunk/sample/pty/shl.rb#L84
       $reader.run
       if writer == 'Exit' then
         $shells[n] = nil
+        $shells.pop until $shells.empty? or $shells[-1]
       end
     end
   when /^q/i

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

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