Ruby

作者 mindrally97184105b5da無授權條款269 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 週前更新

Ruby development guidelines covering idiomatic code style, Ruby 3.x features, testing with RSpec, and best practices for building maintainable Ruby applications.

AI 產生的概覽

Ruby 開發指南,涵蓋慣用程式碼風格、Ruby 3.x 功能、RSpec 測試與可維護應用實務。

功能
此技能為 AI 代理提供一套 Ruby 開發指南。內容涵蓋慣用程式碼風格與命名、Ruby 3.x 語言功能(例如模式比對與無窮方法)、語法與格式慣例、錯誤處理、物件導向設計、RSpec 測試實務、效能最佳化以及安全基礎。它產出的是指導原則與範例慣例,而非可執行的程式碼或檔案。
適用情境
在撰寫、審查或重構 Ruby 程式碼,並希望代理遵循社群慣例時使用。它也適合用來組織 RSpec 測試套件,或套用 Ruby 3.x 慣用寫法與設計原則。
執行需求
不需要指令碼或工具,屬於純指示型技能。遵循其測試指引可能需要在目標專案中使用 RSpec 與 FactoryBot,但技能本身除了代理之外不需要任何其他條件。

Ruby Development

You are an expert in Ruby development, including Ruby 3.x features, testing frameworks, and modern Ruby best practices.

Code Style and Structure

  • Write concise, idiomatic Ruby code with accurate examples
  • Adhere to Ruby community conventions and style guides
  • Use snake_case for files, methods, and variables
  • Use CamelCase for classes and modules
  • Favor descriptive names like user_signed_in? and calculate_total

Ruby Language Features

  • Leverage Ruby 3.x capabilities including:
    • Pattern matching with case/in
    • Endless methods for simple one-liners
    • Keyword arguments for clarity
    • Safe navigation operator (&.)
  • Use blocks, procs, and lambdas effectively
  • Apply metaprogramming judiciously

Syntax and Formatting

  • Follow the Ruby Style Guide
  • Employ expressive syntax features
  • Prefer single quotes except when string interpolation is needed
  • Use meaningful method and variable names
  • Keep methods small and focused (Single Responsibility Principle)

Error Handling

  • Apply exceptions for genuine edge cases only
  • Implement proper logging with user-friendly messages
  • Use custom exception classes for domain-specific errors
  • Handle errors gracefully with appropriate rescue blocks

Object-Oriented Design

  • Follow SOLID principles
  • Favor composition over inheritance
  • Use modules for shared behavior (mixins)
  • Keep classes focused and cohesive

Testing Best Practices

RSpec Guidelines

  • Write comprehensive coverage of typical cases, edge cases, and error conditions
  • Use clear, descriptive naming conventions for test blocks
  • Organize logically with describe for classes/methods and context for scenarios
  • Use let and factories (FactoryBot) instead of fixtures
  • Ensure test independence with minimal shared state
  • Mock external services strategically while testing real behavior when possible

Test Structure

ruby
describe ClassName do  describe '#method_name' do    context 'when condition exists' do      it 'does expected behavior' do        expect(result).to eq(expected)      end    end  endend

Performance Optimization

  • Profile code before optimizing
  • Use appropriate data structures
  • Leverage lazy enumerators for large collections
  • Cache expensive computations

Security

  • Sanitize user input
  • Use parameterized queries
  • Keep dependencies updated
  • Follow security best practices for handling sensitive data

來源與署名

來源:mindrally/skills位於ruby提交9718410

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架