summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sample/occur2.rb4
-rw-r--r--sample/pi.rb2
-rw-r--r--sample/rcs.rb20
-rw-r--r--sample/time.rb2
-rw-r--r--sample/trojan.rb2
-rw-r--r--sample/tsvr.rb6
6 files changed, 13 insertions, 23 deletions
diff --git a/sample/occur2.rb b/sample/occur2.rb
index b8ecf70904..53885c0ba7 100644
--- a/sample/occur2.rb
+++ b/sample/occur2.rb
@@ -2,9 +2,9 @@
# usege: ruby occur2.rb file..
freq = {}
while gets()
- for word in $_.split(/\W+/)
+ for word in split(/\W+/)
begin
- freq[word] = freq[word] + 1
+ freq[word] += 1
rescue NameError
freq[word] = 1
end
diff --git a/sample/pi.rb b/sample/pi.rb
index 49067cc347..63be974285 100644
--- a/sample/pi.rb
+++ b/sample/pi.rb
@@ -2,7 +2,7 @@
k, a, b, a1, b1 = 2, 4, 1, 12, 4
-while TRUE
+loop do
# Next approximation
p, q, k = k*k, 2*k+1, k+1
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
diff --git a/sample/rcs.rb b/sample/rcs.rb
index 7c091936f3..0bdf81c45d 100644
--- a/sample/rcs.rb
+++ b/sample/rcs.rb
@@ -8,22 +8,23 @@ w = 20.0 # distance between eyes
h =1.0 # distance from screen and base plane
d = 0.2 # z value unit
ss="abcdefghijklmnopqrstuvwxyz0123456789#!$%^&*()-=\\[];'`,./"
-rnd = srand()
+rnd = srand() # You don't actually need this in ruby - srand() is called
+ # on the first call of rand().
while gets()
# print($_)
xr = -hdw; y = h * 1.0; maxxl = -999
- s = "";
+ s = ""
while xr < hdw
x = xr * (1 + y) - y * w / 2
i = (x / (1 + h) + sw / 2)
- if (1 < i && i < $_.length);
+ if (1 < i && i < $_.length)
c = $_[i, 1].to_i
else
c = 0
end
y = h - d * c
- xl = xr - w * y / (1 + y);
+ xl = xr - w * y / (1 + y)
if xl < -hdw || xl >= hdw || xl <= maxxl
tt = rand(ss.length)
c = ss[tt, 1]
@@ -36,14 +37,3 @@ while gets()
end
print(s, "\n")
end
-
-
-
-
-
-
-
-
-
-
-
diff --git a/sample/time.rb b/sample/time.rb
index 1624fdf992..84fa9e1a8d 100644
--- a/sample/time.rb
+++ b/sample/time.rb
@@ -5,4 +5,4 @@ system(cmd)
e = Time.now
ut, st, cut, cst = Time.times.to_a
total = (e - b).to_f
-printf STDERR, "%11.1f real %11.1f user %11.1f sys\n", total, cut, cst
+STDERR.printf "%11.1f real %11.1f user %11.1f sys\n", total, cut, cst
diff --git a/sample/trojan.rb b/sample/trojan.rb
index 6e9b18f502..3a35ac21c2 100644
--- a/sample/trojan.rb
+++ b/sample/trojan.rb
@@ -5,7 +5,7 @@ path = ENV['PATH'].split(File::PATH_SEPARATOR)
for dir in path
if File.directory?(dir)
for f in d = Dir.open(dir)
- fpath = dir+"/"+f
+ fpath = File.join(dir, f)
if File.file?(fpath) && (File.stat(fpath).mode & 022) != 0
printf("file %s is writable from other users\n", fpath)
end
diff --git a/sample/tsvr.rb b/sample/tsvr.rb
index 8b019bdb71..52cdd32dce 100644
--- a/sample/tsvr.rb
+++ b/sample/tsvr.rb
@@ -8,11 +8,11 @@ addr = gs.addr
addr.shift
printf("server is on %s\n", addr.join(":"))
-while TRUE
+loop do
Thread.start(gs.accept) do |s|
print(s, " is accepted\n")
- while s.gets
- s.write($_)
+ while line = s.gets
+ s.write(line)
end
print(s, " is gone\n")
s.close