Token导航 LogoToken导航TokenDH.com
前端设计需要联网github未标认证来源可访问许可证需确认审计提醒

ruby-refactoring-expertRuby refactoring expert 命令行

Agent Skill

ruby-refactoring-expert 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

8,388

周安装

312

GitHub Stars

4

下载量

2,167
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:ruby-refactoring-expert(Ruby refactoring expert 命令行)
来源仓库:https://github.com/ag0os/rails-dev-plugin
仓库路径:skills/ruby-refactoring-expert
安装命令:
npx skills add https://github.com/ag0os/rails-dev-plugin --skill 'Ruby Refactoring Expert'
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/ag0os/rails-dev-plugin --skill 'Ruby Refactoring Expert'

简介

用于处理 GitHub 仓库协作信息和代码审查任务。

  • 适合在 AI 宿主中管理项目状态和代码变更事项。
  • 通过 GitHub 仓库安装,使用 npx skills add 命令添加技能。
  • 需确认对目标仓库的操作权限和访问范围。
  • 注意评估对代码库的实际修改风险。ruby-refactoring-expert 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Ruby Refactoring Expert

Systematic code improvement using principles from Ruby Science and established refactoring patterns.

When to Use This Skill

  • Reviewing recently written code for quality and maintainability
  • Identifying code smells in Ruby/Rails code
  • Planning refactoring strategy for complex classes or methods
  • Improving test coverage and structure
  • Analyzing code complexity and suggesting simplifications
  • Ensuring code follows Ruby idioms and Rails conventions

Refactoring Methodology

1. Identify Code Smells

Systematically scan for anti-patterns and problematic code structures. See code-smells.md for complete catalog.

Common code smells:

  • Large Class: Class > 100 lines or many instance variables
  • Long Method: Method > 10-15 lines or requires scrolling
  • Long Parameter List: Method takes > 3 parameters
  • Feature Envy: Method uses another object's data more than its own
  • Data Clumps: Same group of parameters appearing together
  • Primitive Obsession: Using primitives instead of objects
  • Shotgun Surgery: Change requires many small edits in many places
  • Divergent Change: Class changes for different reasons

2. Prioritize Issues

Rank problems by impact on maintainability, performance, and business value.

Priority levels:

  • High: Security issues, major maintainability problems, performance bottlenecks
  • Medium: Code complexity, duplication, testing gaps
  • Low: Style improvements, minor optimizations

Focus on high-impact, low-risk refactorings first.

3. Propose Solutions

For each issue, suggest specific refactoring patterns with concrete examples.

See refactoring-patterns.md for complete pattern catalog.

4. Consider Trade-offs

Be pragmatic:

  • Will refactoring introduce complexity?
  • Is there performance overhead?
  • What's the benefit vs. cost?
  • Is this over-engineering?

Remember: Perfect code is less important than working, maintainable code the team can understand.

5. Ensure Test Coverage

Before refactoring:

  • ✅ Verify existing tests cover the code
  • ✅ Suggest additional tests for insufficient coverage
  • ✅ Ensure tests pass before and after refactoring
  • ✅ Refactor in small, verifiable steps

Quick Refactoring Reference

Extract Method

When: Method > 10-15 lines or does multiple things

# Before
def calculate_total
  subtotal = line_items.sum(&:amount)
  tax = subtotal * tax_rate
  shipping = calculate_shipping(subtotal)
  subtotal + tax + shipping
end

# After
def calculate_total
  subtotal + tax + shipping_cost
end

private

def subtotal
  line_items.sum(&:amount)
end

def tax
  subtotal * tax_rate
end

def shipping_cost
  calculate_shipping(subtotal)
end

Extract Class

When: Class > 100 lines or has multiple responsibilities

# Before: User class handling authentication AND profile management
class User < ApplicationRecord
  def authenticate(password)
    # Authentication logic
  end

  def update_profile(params)
    # Profile logic
  end

  def send_welcome_email
    # Email logic
  end
end

# After: Separated concerns
class User < ApplicationRecord
  has_one :user_profile

  def authenticate(password)
    # Authentication only
  end
end

class UserProfile < ApplicationRecord
  belongs_to :user

  def update(params)
    # Profile management
  end
end

class UserNotifier
  def self.send_welcome(user)
    # Email logic
  end
end

Extract Service Object

When: Logic spans multiple models or has complex orchestration

# Before: Fat controller or model method
class PolicyRenewalService
  def initialize(policy, new_expiry_date)
    @policy = policy
    @new_expiry_date = new_expiry_date
  end

  def call
    return failure("Not renewable") unless @policy.renewable?

    ApplicationRecord.transaction do
      archive_old_policy
      update_policy
      create_invoice
      send_notifications
    end

    success(@policy)
  rescue StandardError => e
    failure(e.message)
  end
end

Replace Conditional with Polymorphism

When: Complex conditionals based on type

# Before: Type checking
def calculate_premium
  case insurance_type
  when 'auto'
    base_rate * vehicle_factor * driver_age_factor
  when 'home'
    base_rate * property_value_factor * location_risk
  when 'life'
    base_rate * age_factor * health_factor
  end
end

# After: Polymorphism
class AutoInsurancePolicy < Insurance::Policy
  def calculate_premium
    base_rate * vehicle_factor * driver_age_factor
  end
end

class HomeInsurancePolicy < Insurance::Policy
  def calculate_premium
    base_rate * property_value_factor * location_risk
  end
end

Introduce Parameter Object

When: Method has > 3 parameters or parameter groups appear together

# Before
def create_policy(policy_number, effective_date, expiry_date, premium, person_id, company_id)
  # ...
end

# After
class PolicyAttributes
  attr_reader :policy_number, :effective_date, :expiry_date,
              :premium, :person_id, :company_id

  def initialize(params)
    @policy_number = params[:policy_number]
    @effective_date = params[:effective_date]
    # ...
  end

  def valid?
    # Validation logic
  end
end

def create_policy(attributes)
  return unless attributes.valid?
  # ...
end

Ruby and Rails Best Practices

Ruby Idioms

Use blocks and enumerables:

# ✅ Good
users.select(&:active?).map(&:email)

# ❌ Bad
result = []
users.each do |user|
  result << user.email if user.active?
end

Use symbols for keys:

# ✅ Good
{ name: 'John', age: 30 }

# ❌ Bad
{ 'name' => 'John', 'age' => 30 }

Rails Conventions

Skinny controllers, focused models:

  • Controllers: HTTP handling, authorization
  • Models: Domain logic, associations
  • Services: Multi-model operations

Use scopes for queries:

# ✅ Good
class Policy < ApplicationRecord
  scope :active, -> { where(status: 'active') }
  scope :expiring_soon, -> { where('expiry_date < ?', 30.days.from_now) }
end

# ❌ Bad
def self.active_policies
  where(status: 'active')
end

SOLID Principles

  • Single Responsibility: One class = one reason to change
  • Open/Closed: Open for extension, closed for modification
  • Liskov Substitution: Subclasses should be substitutable
  • Interface Segregation: Many specific interfaces > one general
  • Dependency Inversion: Depend on abstractions, not concretions

Output Format

When providing refactoring recommendations:

1. Code Smell Analysis

List identified issues with severity (High/Medium/Low) and location

2. Refactoring Plan

Prioritized list of refactoring steps

3. Implementation Examples

Concrete before/after code samples

4. Test Considerations

Required test changes or additions

5. Migration Strategy

How to safely deploy changes

Quality Checks

Before finalizing recommendations:

  • ✅ All tests still pass
  • ✅ No performance regressions
  • ✅ Code complexity improves (ABC score, cyclomatic complexity)
  • ✅ Code is more readable and maintainable
  • ✅ Business logic unchanged (unless explicitly intended)

Related Documentation

Quick Decision Matrix

SmellPatternWhen to Use
Long MethodExtract MethodMethod > 10-15 lines
Large ClassExtract ClassClass > 100 lines
Long Parameter ListParameter Object> 3 parameters
Feature EnvyMove MethodUses other object's data
Primitive ObsessionExtract Value ObjectPrimitives with behavior
Complex ConditionalPolymorphismType-based conditionals
Duplicated CodeExtract Method/ModuleSame code in 2+ places

Communication Style

  • Use clear, technical language for experienced developers
  • Provide concrete examples over abstractions
  • Reference Ruby Science principles by name
  • Include links to documentation when relevant
  • Be decisive but explain reasoning

Ask questions when uncertain about:

  • Business requirements
  • Existing constraints
  • Team preferences
  • Performance requirements

Remember: The goal is maintainable code that the team understands, not perfect code.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.9%
按下载量换算735

Claude

32.2%
按下载量换算698

Cursor

20.3%
按下载量换算440

Gemini CLI

10.24%
按下载量换算222

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills