refactor by pokotyamu#10
Open
pokotyamu wants to merge 5 commits into
Open
Conversation
pokotyamu
commented
Dec 5, 2017
| @@ -0,0 +1,4 @@ | |||
| def transpose(source) | |||
| matrix = source.split("\n").map {|s| s.split(" ")} | |||
| matrix.transpose.map {|s| s.join(" ")}.join("\n") | |||
Author
There was a problem hiding this comment.
プレーンテキストから、行列への変換(その逆の変換)部分は他のメソッドで使用することがあれば、そのタイミングでメソッド化すればいいと思うので、今はこのままで問題ないと思います!
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.
リファクタ案です 👍
プログラムの最終行には、改行を入れるようにしましょう。
これがなくてもプログラムとしては、大丈夫だけど、プログラムを書く時のお約束事のようなものなので、エディター側で保存する時に自動的に補完されるような設定を書くと良いと思います!
詳しく知りたいなら
EOF new lineなどで検索するとわかると思います:pray:テストケースを条件毎に分けて書くことで、それがどんなことをテストしているか?というのがコードを読まずに分かるという利点があります🙋
今回のケースのように転置行列を求めるメソッドが既に Array クラスに用意されているので、こちらを使う方が良さそうです。
instance method Array#transpose (Ruby 2.4.0)
arrayだとだたの配列の印象がしたので、行列を意味するmatrixに変更しました♻️メソッド名としては動詞のほうが適しているので、名詞の
transportより動詞のtransposeに変更しました♻️