# モジュールの抽出

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

> **TL;DR**
> `リファクタリング | 抽出 / 導入 | モジュール`

モジュールの抽出 リファクタリングにより、選択したクラスから特定のメンバーを別々のモジュールに抽出することができます。

モジュールを抽出するには

Procedure:

1. クラス名またはクラス内の任意の場所にキャレットを置きます。

2. メインメニューから  `リファクタリング | 抽出 / 導入 | モジュール`  を選択します。

3. モジュールの抽出   ダイアログで、モジュール名、モジュールを配置するディレクトリを指定し、追加するメンバーを選択します。

![モジュールの抽出ダイアログ](https://resources.jetbrains.com/help/img/idea/2026.3/rm_refactoring_extract_module_dialog.png)

OK   をクリックしてください。 RubyMine はモジュールを別のファイルに作成します。

## サンプル

Before:

```RUBY
# 'cat.rb' file
class Cat
    def breathe
        puts "inhale and exhale"
    end
    def speak
        puts "Meow"
    end
end

```

After:

```RUBY
# 'cat.rb' file
class Cat
    include Animal

    def speak
        puts "Meow"
    end
end

#
# 'animal.rb' file
module Animal
    def breathe
        puts "inhale and exhale"
    end
end

```

