# Extract field

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/ruby/2026.3/llms.txt).

> **TL;DR**
> `Refactor | Extract/Introduce | Field`
>
>
>
> `Ctrl+Alt+F` (Windows), `⌘ ⌥ F` (macOS), `⌘ ⌥ F` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ F` (macOS System Shortcuts), `Ctrl+Alt+F` (XWin), `Ctrl+Alt+F` (GNOME), `Ctrl+Alt+F` (KDE), `Ctrl+Alt+F` (Emacs), `Ctrl+Alt+F` (Sublime Text), `Ctrl+Alt+F` (Sublime Text (macOS)), `Ctrl+R, F` (Visual Studio), `⌘ R, F` (Visual Studio (macOS)), `Ctrl+Alt+F` (TextMate), `Alt+Shift+E` (NetBeans), `Ctrl+Alt+F` (Eclipse), `⌘ ⌥ F` (Eclipse (macOS))

The Extract Field refactoring lets you extract a specified value to an instance or class variable.

The animation below demonstrates how to extract a specific word from a string to an instance variable:

![extract field](https://resources.jetbrains.com/help/img/idea/2026.3/rm_refactoring_extract_field.animated.gif)

To extract a field:

Procedure:

1. Select a value to refactor or place the caret at a string containing the required value.

2. In the main menu, go to `Refactor | Extract/Introduce | Field` `Ctrl+Alt+F` (Windows), `⌘ ⌥ F` (macOS), `⌘ ⌥ F` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ F` (macOS System Shortcuts), `Ctrl+Alt+F` (XWin), `Ctrl+Alt+F` (GNOME), `Ctrl+Alt+F` (KDE), `Ctrl+Alt+F` (Emacs), `Ctrl+Alt+F` (Sublime Text), `Ctrl+Alt+F` (Sublime Text (macOS)), `Ctrl+R, F` (Visual Studio), `⌘ R, F` (Visual Studio (macOS)), `Ctrl+Alt+F` (TextMate), `Alt+Shift+E` (NetBeans), `Ctrl+Alt+F` (Eclipse), `⌘ ⌥ F` (Eclipse (macOS)).

3. (Optional) If you place the caret at a place containing several expressions available for extracting, select the required expression and press `Enter` (Windows), `⏎` (macOS), `⏎` (IntelliJ IDEA Classic (macOS)), `⏎` (macOS System Shortcuts), `Enter` (XWin), `Enter` (GNOME), `Enter` (KDE), `Enter` (Emacs), `Enter` (Sublime Text), `⏎` (Sublime Text (macOS)), `Enter` (Visual Studio), `⏎` (Visual Studio (macOS)), `Enter` (TextMate), `Enter` (NetBeans), `Enter` (Eclipse), `⏎` (Eclipse (macOS)).

4. (Optional) If more than one occurrence of the expression is found, specify whether you wish to replace only the selected occurrence or all the found occurrences with the new variable:

![replace all occurrences](https://resources.jetbrains.com/help/img/idea/2026.3/rm_refactoring_extract_field.png)

5. Specify the instance/class variable name and press `Enter` (Windows), `⏎` (macOS), `⏎` (IntelliJ IDEA Classic (macOS)), `⏎` (macOS System Shortcuts), `Enter` (XWin), `Enter` (GNOME), `Enter` (KDE), `Enter` (Emacs), `Enter` (Sublime Text), `⏎` (Sublime Text (macOS)), `Enter` (Visual Studio), `⏎` (Visual Studio (macOS)), `Enter` (TextMate), `Enter` (NetBeans), `Enter` (Eclipse), `⏎` (Eclipse (macOS)).

## Example

Before:

```RUBY
class Hello
    def greet
        puts "Hello from JetBrains"
    end
    def bye
        puts "Goodbye from JetBrains"
    end
end
```

After:

```RUBY
class Hello
    def initialize
        @name = "JetBrains"
    end

    def greet
        puts "Hello from #{@name}"
    end
    def bye
        puts "Goodbye from #{@name}"
    end
end
```

## See also

### Reference

