Refactor dir.rb sample (#6977) [ci skip]
* Refactor dir.rb sample The original (1998) sample with a for-loop and use of case/when isn't what we'd write nowadays * [DOC] Update sample/dir.rb [ci skip] Do not leave a `Dir` opened. * [DOC] Update sample/dir.rb [ci skip] Fix ArgumentError. --------- Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
This commit is contained in:
parent
3376eca80a
commit
f03dd4ee77
Notes:
git
2023-02-15 03:42:15 +00:00
Merged-By: hsbt <hsbt@ruby-lang.org>
@ -1,12 +1,7 @@
|
|||||||
# directory access
|
# directory access
|
||||||
# list all files but .*/*~/*.o
|
# list all files but .*/*~/*.o
|
||||||
dirp = Dir.open(".")
|
Dir.foreach(".") do |file|
|
||||||
for f in dirp
|
unless file.start_with?('.') or file.end_with?('~', '.o')
|
||||||
case f
|
puts file
|
||||||
when /\A\./, /~\z/, /\.o\z/
|
|
||||||
# do not print
|
|
||||||
else
|
|
||||||
print f, "\n"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
dirp.close
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user