RubyMine 2025.2 Help

提取模块

提取模块重构允许您将选定类中的某些成员提取到一个单独的模块中。

要提取模块:

  1. 将插入符号放置在类名或类中的任意位置。

  2. 从主菜单中选择 重构 | 提取/引入 | 模块

  3. 提取模块 对话框中,指定模块名称、应放置的目录,并选择要添加的成员:

    提取模块对话框

    点击 确定。 RubyMine 将在一个单独的文件中创建一个模块。

示例

# 'cat.rb' file class Cat def breathe puts "inhale and exhale" end def speak puts "Meow" end end
# '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
最后修改日期: 2025年 9月 26日