{"comment":{"url":"https://api.github.com/repos/iceland101113/cathaybk/comments/28487723","html_url":"https://github.com/iceland101113/cathaybk/commit/2fc2d3e70dc9ffac1ee441f9265fa284b39c2229#commitcomment-28487723","id":28487723,"user":{"login":"ihower","id":4557,"avatar_url":"https://avatars3.githubusercontent.com/u/4557?v=4","gravatar_id":"","url":"https://api.github.com/users/ihower","html_url":"https://github.com/ihower","followers_url":"https://api.github.com/users/ihower/followers","following_url":"https://api.github.com/users/ihower/following{/other_user}","gists_url":"https://api.github.com/users/ihower/gists{/gist_id}","starred_url":"https://api.github.com/users/ihower/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ihower/subscriptions","organizations_url":"https://api.github.com/users/ihower/orgs","repos_url":"https://api.github.com/users/ihower/repos","events_url":"https://api.github.com/users/ihower/events{/privacy}","received_events_url":"https://api.github.com/users/ihower/received_events","type":"User","site_admin":false},"position":76,"line":218,"path":"app/controllers/cathaybk_controller.rb","commit_id":"2fc2d3e70dc9ffac1ee441f9265fa284b39c2229","created_at":"2018-04-09T13:46:34Z","updated_at":"2018-04-09T13:46:34Z","author_association":"NONE","body":"這個方法太 implicit 了，它隱性地依賴了兩個參數 @ip_lat 和 @ip_lng，並隱性地設定了四個 @bank_ 變數。我如果要 reuse 這個方法，很難第一時間看出我需要先設定 @ip_lat 和 @ip_lng 才能呼叫這個方法，並且它也固定會設定那四個 @bank_x 變數名。\r\n\r\n可以改成 \r\n\r\n     def cal_nearbank(ip_lat, ip_lng)\r\n       # ...\r\n       return bank[b_where], bank_p[b_where], data1[b_where], data2[b_where]/60 \r\n    end\r\n\r\n這樣呼叫的時候\r\n\r\n   @bank_near_name, @bank_near, @bank_distance, @bank_duration = cal_nearbank(@ip_lat, @ip_lng)\r\n\r\n然後你可以進一步把這個方法搬到 model 去，例如變成 Addresslanlng 的 class method。"}}
{"actor":{"display_login":"ihower"}}