[chooyan-eng] suggestions to make code better#4
Open
chooyan-eng wants to merge 1 commit intoJunichiIto:masterfrom
Open
[chooyan-eng] suggestions to make code better#4chooyan-eng wants to merge 1 commit intoJunichiIto:masterfrom
chooyan-eng wants to merge 1 commit intoJunichiIto:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
lib/transport.rbへの修正
2行目のsplit(" ")を簡略化しました
APIドキュメントを見ると、splitはpetternをnilにする(省略する)と半角スペースで区切る挙動になります。
そのため、2行目は
と書くことができ、さらにブロック内の処理が引数なしのメソッド呼び出しのみの場合は
&:を使ってブロックを省略できるため、以下のように簡略化できます。3~8行目の転置処理をmapメソッドを利用して修正しました
ここは元の行列を表す配列から新しい配列を作成する処理なので、
mapを活用することでソースコードを簡略化することができます。結果を保持するための空の配列を定義する必要もなくなり、ソースコードがすっきりします。変数名を読みやすく修正しました
このメソッドは行列を表す多次元配列を操作する処理ということで少し内容のイメージがしづらいため、なるべく変数名はその内容を表す単語にしておくことで読む側が楽になります。
行列は"matrix"、行は"row"、個々の値は"n"として名前を修正しています。
また、「転置」にあたる単語は"transport"ではなく"transpose"のようですので、ソースコード全体を通してこちらを使った方が良いでしょう。
転置行列 | Wikipedia
test/transport_test.rbへの修正
テストケースを分割しました
1つ目のテスト(3 x 3の行列)と2つ目のテスト(3 x 4の行列)では試験対象のデータが変わりますので、テストケースも分割しておいた方が良いでしょう。