diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb index 1c6d6fbad1..74e615a289 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 [ for Systemdate] (YYYYMMDD) : ") - if (si = STDIN.gets.chop) != "" + STDERR.print("Date [ 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 4f96ca4089..0f3d17bf19 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 af566056b7..6169861abc 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