summaryrefslogtreecommitdiff
path: root/sample/pty/expect_sample.rb
diff options
context:
space:
mode:
Diffstat (limited to 'sample/pty/expect_sample.rb')
-rw-r--r--sample/pty/expect_sample.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/sample/pty/expect_sample.rb b/sample/pty/expect_sample.rb
index d3b072b83c..199d98b79c 100644
--- a/sample/pty/expect_sample.rb
+++ b/sample/pty/expect_sample.rb
@@ -1,9 +1,10 @@
+# frozen_string_literal: true
#
# sample program of expect.rb
#
# by A. Ito
#
-# This program reports the latest version of ruby interpreter
+# This program reports the latest version of Ruby interpreter
# by connecting to ftp server at ruby-lang.org.
#
require 'pty'
@@ -23,8 +24,17 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
username = 'guest'
end
- r_f.expect(/^(Name).*: |(word):|> /) do
- w_f.puts($1 ? "ftp" : $2 ? "#{username}@" : "cd pub/ruby")
+ r_f.expect(/^Name.*: /) do
+ w_f.puts("ftp")
+ end
+ r_f.expect(/word:/) do
+ w_f.puts("#{username}@")
+ end
+ r_f.expect(/> /) do
+ w_f.puts("cd pub/ruby")
+ end
+ r_f.expect("> ") do
+ w_f.print "pass\n"
end
r_f.expect("> ") do
w_f.print "dir\n"