# 4. Refactoring

### Refactoring menu

1. `Ctl + T`
   * 사용 가능한 리팩토링 목록이 나온다.

### Rename

> 내 키보드로는 이용하지 못함.

1. `Shift + F6`
   * `Rename` 하기 원하는 곳에 커서를 위치시키고 단축키를 입력하자.
   * `RubyMine` 은 수정하기 전에 먼저 사용자에게 확인시켜주는 단계가 있다.

### Extract variable

> 똑같은 `rvlaue`를 여러 번 쓰는건 클린코드에 맞지 않다. 하나의 변수로 선언하고 사용하자.

아래의 코드에서 `array[i + 1]` 은 변수로 선언되지 않은채 너무 많이 사용된다. 한번에 변수화 시키는 방법은 없을까?

```ruby
if array[i] > array[i + 1]
  array[i], array[i + 1] = array[i + 1], array[i]
  swapped = true
end
```

1. `com + opt + V`
   * 수정하길 원하는 곳에 커서를 옮기고 단축키를 누르자.
   * 그러면 `expression` 이라는 목록이 나온다. 원하는 것을 선택하자.
   * 그러면 변수화가 되는데, 이 때 변수명도 지을 수 있다.

### Extract method

```ruby
array[i], array[i + 1] = array[i + 1], array[i]
```

위의 코드는 추상화를 하면 굉장히 좋을거 같다. 근데 귀찮아.. 한번에 해주는 마법같은 단축키는 없을까? 있다!

1. `com + opt + M`
   * 함수화를 원하는 라인에 단축키를 누르자.
   * 그러면 어떻게 할 지 다 나온다\~


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://simian114.gitbook.io/blog/undefined-1/odds_and_ends/ide/rubymine/4.-refactoring.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
