|
|
|
|
|
by area51org
1283 days ago
|
|
I appreciate the Ruby love in this post, but it's worth pointing out that the author is clearly new to the language. I say that because he writes Ruby as if he's writing some other language, and not idiomatic Ruby. This: dirp = Dir.open(".")
for f in dirp
case f
when /\.rb\z/
print f, "\n"
else
# do not print
end
end
dirp.close
Could be made much more Ruby-native (and simpler!) as: Dir.open('.').each do |f|
puts f if f.match?(/\.rb\z/)
end
My point isn't to play the "I know the language better than you, so nyah nyah" game, just to suggest that if the author likes Ruby as much as he says, he should learn it better. |
|
That pretty not great ruby wasn't written by the author -- it's actually included in a "sample" file with the ruby distro?
https://github.com/ruby/ruby/blob/ruby_3_1/sample/dir.rb
A file whose commit history shows... it's part of the very first commit recorded in git history, in 1998 by matz, the original author of ruby.
I have no idea what's going on in that "sample" folder, very weird.
The OP is simply regurgitating the weird "sample" folder. The "author" of the OP didn't write any of this code. According to git history... matz did?!?