зеркало из https://github.com/github/ruby.git
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:
Родитель
3376eca80a
Коммит
f03dd4ee77
|
@ -1,12 +1,7 @@
|
|||
# directory access
|
||||
# list all files but .*/*~/*.o
|
||||
dirp = Dir.open(".")
|
||||
for f in dirp
|
||||
case f
|
||||
when /\A\./, /~\z/, /\.o\z/
|
||||
# do not print
|
||||
else
|
||||
print f, "\n"
|
||||
Dir.foreach(".") do |file|
|
||||
unless file.start_with?('.') or file.end_with?('~', '.o')
|
||||
puts file
|
||||
end
|
||||
end
|
||||
dirp.close
|
||||
|
|
Загрузка…
Ссылка в новой задаче