summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-19 20:26:16 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-19 20:26:16 +0000
commitd46e835344bc4d43c804d7b2d66145b80ef0c7e3 (patch)
tree7482b5a88aed2c13d2f2e45cf8679fc4a1ec9484 /sample
parentc3cd615aa4a2e52d8943df72a9a55d2607792fe9 (diff)
Strive to give better examples.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
-rw-r--r--sample/biorhythm.rb24
-rw-r--r--sample/clnt.rb10
-rw-r--r--sample/svr.rb4
3 files changed, 20 insertions, 18 deletions
diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb
index 1c6d6fb..74e615a 100644
--- a/sample/biorhythm.rb
+++ b/sample/biorhythm.rb
@@ -79,40 +79,38 @@ else
if $OPT_birthday
bd = Date.new(*parsedate($OPT_birthday))
else
- printf(STDERR, "Birthday (YYYYMMDD) : ")
- if (si = STDIN.gets.chop) != ""
+ STDERR.print("Birthday (YYYYMMDD) : ")
+ unless (si = STDIN.gets.chop).empty?
bd = Date.new(*parsedate(si))
end
end
if !bd
- printf STDERR, "BAD Input Birthday!!\n"
+ STDERR.print "BAD Input Birthday!!\n"
exit()
end
-
+
if $OPT_sdate
dd = Date.today
elsif $OPT_date
dd = Date.new(*parsedate($OPT_date))
else
- printf(STDERR, "Date [<RETURN> for Systemdate] (YYYYMMDD) : ")
- if (si = STDIN.gets.chop) != ""
+ STDERR.print("Date [<RETURN> for Systemdate] (YYYYMMDD) : ")
+ unless (si = STDIN.gets.chop).empty?
dd = Date.new(*parsedate(si))
end
end
- if !dd
- dd = Date.today
- end
+ dd ||= Date.today
if $OPT_v
ausgabeart = "v"
elsif $OPT_g
ausgabeart = "g"
else
- printf(STDERR, "Values for today or Graph (v/g) [default g] : ")
+ STDERR.print("Values for today or Graph (v/g) [default g] : ")
ausgabeart = STDIN.gets.chop
end
end
-if (ausgabeart == "v")
+if ausgabeart == "v"
printHeader(bd.year, bd.month, bd.day, dd - bd, name_of_week(bd))
print "\n"
@@ -128,9 +126,9 @@ else
elsif $OPT_D
display_period = 9
else
- printf(STDERR, "Graph for how many days [default 10] : ")
+ STDERR.printf("Graph for how many days [default 10] : ")
display_period = STDIN.gets.chop
- if (display_period == "")
+ if display_period.empty?
display_period = 9
else
display_period = display_period.to_i - 1
diff --git a/sample/clnt.rb b/sample/clnt.rb
index 4f96ca4..0f3d17b 100644
--- a/sample/clnt.rb
+++ b/sample/clnt.rb
@@ -3,15 +3,19 @@
require "socket"
-host=(if ARGV.length == 2; ARGV.shift; else "localhost"; end)
+if ARGV.length >= 2
+ host = ARGV.shift
+else
+ host = "localhost"
+end
print("Trying ", host, " ...")
STDOUT.flush
s = TCPSocket.open(host, ARGV.shift)
print(" done\n")
print("addr: ", s.addr.join(":"), "\n")
print("peer: ", s.peeraddr.join(":"), "\n")
-while gets()
- s.write($_)
+while line = gets()
+ s.write(line)
print(s.readline)
end
s.close
diff --git a/sample/svr.rb b/sample/svr.rb
index af56605..6169861 100644
--- a/sample/svr.rb
+++ b/sample/svr.rb
@@ -9,7 +9,7 @@ addr.shift
printf("server is on %s\n", addr.join(":"))
socks = [gs]
-while TRUE
+loop do
nsock = select(socks);
next if nsock == nil
for s in nsock[0]
@@ -23,7 +23,7 @@ while TRUE
s.close
socks.delete(s)
else
- if str = s.gets;
+ if str = s.gets
s.write(str)
end
end