I am learning Ruby and found this code sample in some documentation:
require 'find'
total_size = 0
Find.find(ENV["HOME"]) do |path|
if FileTest.directory?(path)
if File.basename(path)[0] == ?.
Find.prune # Don't look any further into this directory.
else
next
end
else
total_size += FileTest.size(path)
end
end
The purpose is to sum up the file sizes of all files in a tree, excluding directories that start with a dot. The line "if File.basename(path)[0] == ?." is obviously performing the directory name test. I would have written it like this:
if File.basename(path)[0] == "."
What does "?."
do? (Could be a typo, I suppose.) I have not seen this syntax described elsewhere.