#!/usr/bin/env ruby
chars = 0
words = 0
lines = 0
# Count the stuff
while line = gets
chars += line.size
words += line.split.size
lines += 1
end
# Display the results
puts "Chars=%s, Words=%s, Lines=%s" % [
chars, words, lines
]
|
|
- Comments begin with "#"
- Notice standard script header line
- Everything is an object
- "a b".size => 3
- "a b".split => ['a', 'b']
- ["a", "b"].size => 2
- No semi-colons needed. Lines continue automatically if needed, otherwise use a "\"
- [a, b, c] is a three element array
|