{"comment":{"url":"https://api.github.com/repos/d1ma-angel/thinknetica/comments/27284808","html_url":"https://github.com/d1ma-angel/thinknetica/commit/898c63980e24405c8b2615f38b601b21d3a5300f#commitcomment-27284808","id":27284808,"user":{"login":"iBublik","id":11278497,"avatar_url":"https://avatars1.githubusercontent.com/u/11278497?v=4","gravatar_id":"","url":"https://api.github.com/users/iBublik","html_url":"https://github.com/iBublik","followers_url":"https://api.github.com/users/iBublik/followers","following_url":"https://api.github.com/users/iBublik/following{/other_user}","gists_url":"https://api.github.com/users/iBublik/gists{/gist_id}","starred_url":"https://api.github.com/users/iBublik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iBublik/subscriptions","organizations_url":"https://api.github.com/users/iBublik/orgs","repos_url":"https://api.github.com/users/iBublik/repos","events_url":"https://api.github.com/users/iBublik/events{/privacy}","received_events_url":"https://api.github.com/users/iBublik/received_events","type":"User","site_admin":false},"position":53,"line":30,"path":"task_03/railway.rb","commit_id":"898c63980e24405c8b2615f38b601b21d3a5300f","created_at":"2018-02-02T07:36:38Z","updated_at":"2018-02-02T07:36:38Z","author_association":"NONE","body":"Чтоб избежать вложенности всего тела метода, можно использовать прием \"guard clause\". Это когда ты сразу делаешь `return` при определенном условии. Тут это так выглядит (заодно отрефакторил метод):\r\n```ruby\r\n# Вычисляем позицию, она пригодится и для проверки, и для вставки\r\ninsert_position = @stations.index(after_station) + 1\r\n# Выходим из метода, чтоб не было вложенности\r\nreturn if insert_position == @stations.size\r\n\r\n@stations.insert(insert_position, station)\r\n```"}}
{"actor":{"display_login":"iBublik"}}