-
Notifications
You must be signed in to change notification settings - Fork 0
-r,-a,-l のオプションに対応やり直し #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
JunichiIto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コメントしました!
| @@ -1,4 +1,3 @@ | |||
| #!/usr/bin/env ruby | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
質問)この行、なぜ消したんでしょう?
| print_l_option_files(file_stats) | ||
| else | ||
| print_no_option_files(file_stats) | ||
| print_not_l_option_files(file_stats) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
man lsで-lの説明を読んでみてください。
たぶんlはlong formatのlだと説明されているはずです。
なので、メソッド名もprint_in_long_format、print_in_short_formatみたいにすると対称性があって良いかもしれません。(好みの問題です)
|
|
||
| def make_file_stats(ls_dir) | ||
| files = fetch_files(ls_dir) | ||
| def make_file_stats(ls_dir, params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「オブジェクトを作る」の「作る」はmakeよりもbuildが使われることが多いので、ここもbuild_xxxにした方がいいかも
| files = if params['a'] | ||
| Dir.glob("#{ls_dir}/*", File::FNM_DOTMATCH).sort | ||
| else | ||
| Dir.glob("#{ls_dir}/*").sort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flagのデフォルト値は数値の0のようです。
https://docs.ruby-lang.org/ja/latest/method/Dir/s/=5b=5d.html
なので、
flags = params['a'] ? File::FNM_DOTMATCH : 0のようにすると、ここのコードがよりDRYにできそうです
あと、前回紹介したFile.joinを使ってパスを連結してみてください〜。
| if params['r'] | ||
| files.reverse | ||
| else | ||
| files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
三項演算子を使ってもいいかもしれませんね
lコマンドの -r,-a,-l のオプションに対応しましたので、確認お願いいたします。