본문으로 건너뛰기
Skillpedia
일반 코딩48k · #5897

ruby

하는 일

이 가이드는 Ruby 프로그래머가 더 깔끔하고 효율적인 코드를 작성하도록 돕습니다. 언어에 내장된 도구를 사용해 작업을 더 단순하고 빠르게 처리하는 방법을 보여 줍니다.

사용하는 경우

  • ✓Ruby 코드를 더 읽기 쉽게 만들고 싶을 때.
  • ✓Ruby 코드 작성의 모범 사례를 배울 때.
  • ✓Ruby 코드의 성능을 최적화하려는 경우.

스킬 링크

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/ruby/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/ruby/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“항목을 묶을 때 더 관용적인 Ruby 코드를 작성하려면 어떻게 해야 하나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

AI는 '나쁜' 코드 예시와 좋은 Ruby 예시를 비교합니다. 작업을 더 간결하고 효율적으로 끝내는 특정 언어 메서드를 사용하도록 제안합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Ruby: Idiomatic Efficiency Reference

When to Use

  • Use this skill when the task matches this description: Language-specific super-code guidelines for ruby.

Table of Contents

  1. Enumerable & Collections
  2. Blocks, Procs & Lambdas
  3. String Handling
  4. Error Handling
  5. Classes & Modules
  6. Ruby Idioms
  7. Anti-patterns specific to Ruby

1. Enumerable & Collections {#enumerable}

# ❌ Manual accumulation
result = []
items.each do |item|
  result << item.name.upcase if item.active?
end

# ✅
result = items.select(&:active?).map { |i| i.name.upcase }
# ❌ Manual grouping
grouped = {}
items.each do |item|
  grouped[item.category] ||= []
  grouped[item.category] << item
end

# ✅
grouped = items.group_by(&:category)
# ❌ Manual sum
total = 0
orders.each { |o| total += o.amount }

# ✅
total = orders.sum(&:amount)
# ❌ Checking existence then accessing
if hash.key?(key)
  value = hash[key]
end

# ✅
value = hash[key] # returns nil if missing
# or with default:
value = hash.fetch(key, default_value)
# or raising on missing:
value = hash.fetch(key) # raises KeyError

Prefer map/select/reject/sum over manual loops. Use &:method for single-method blocks.


2. Blocks, Procs & Lambdas {#blocks}

# ❌ Explicit block-to-proc conversion when unnecessary
items.map { |item| item.to_s }

# ✅
items.map(&:to_s)
# ❌ Proc.new when lambda is safer (arity check + return behavior)
handler = Proc.new { |x| x * 2 }

# ✅
handler = ->(x) { x * 2 }
# ❌ Multi-line block with { }
items.map { |item|
  result = transform(item)
  validate(result)
  result
}

# ✅ — do/end for multi-line, { } for single-line
items.map do |item|
  result = transform(item)
  validate(result)
  result
end

3. String Handling {#strings}

# ❌ String concatenation in loop
result = ""
items.each { |i| result += i.name + ", " }

# ✅
result = items.map(&:name).join(", ")
# ❌ String concatenation for assembly
greeting = "Hello, " + name + "! You have " + count.to_s + " messages."

# ✅
greeting = "Hello, #{name}! You have #{count} messages."
# ❌ Mutable string where frozen is fine (Ruby 3+ encourages frozen)
SEPARATOR = ", "

# ✅
SEPARATOR = ", ".freeze
# or add `# frozen_string_literal: true` at file top

Use heredocs (<<~HEREDOC) for multi-line strings. <<~ strips indentation.


4. Error Handling {#errors}

# ❌ Rescuing Exception (catches EVERYTHING including SignalException, SystemExit)
begin
  risky
rescue Exception => e
  log(e)
end

# ✅ — rescue StandardError (the default)
begin
  risky
rescue StandardError => e
  log(e)
  raise
end
# or just: rescue => e (same as StandardError)
# ❌ Using rescue as flow control
begin
  value = hash.fetch(key)
rescue KeyError
  value = default
end

# ✅
value = hash.fetch(key, default)
# ❌ Inline rescue hiding errors
result = dangerous_operation rescue nil

# ✅ — inline rescue only for truly trivial fallbacks
result = Integer(input) rescue nil  # acceptable for parsing

5. Classes & Modules {#classes}

# ❌ Manual accessors
class User
  def name
    @name
  end
  def name=(value)
    @name = value
  end
end

# ✅
class User
  attr_accessor :name
end
# ❌ Deep inheritance for shared behavior
class Animal; end
class Pet < Animal; end
class Dog < Pet; end

# ✅ — mixins for shared behavior, inheritance for "is-a"
module Trainable
  def train = puts("Training #{name}")
end

class Dog
  include Trainable
  attr_reader :name
  def initialize(name) = @name = name
end
# ❌ Class with only class methods (namespace via class)
class MathUtils
  def self.square(x) = x * x
  def self.cube(x) = x ** 3
end

# ✅
module MathUtils
  module_function
  def square(x) = x * x
  def cube(x) = x ** 3
end

6. Ruby Idioms {#idioms}

# ❌ Explicit boolean return
def active?
  if status == :active
    true
  else
    false
  end
end

# ✅
def active? = status == :active
# ❌ nil check before method call
if user && user.name
  puts user.name
end

# ✅ (Ruby 2.3+)
puts user&.name if user&.name
# or with safe navigation:
user&.name&.then { |n| puts n }
# ❌ Conditional assignment verbosely
if @cache.nil?
  @cache = expensive_compute
end

# ✅
@cache ||= expensive_compute

…
자주 묻는 질문

프로그래밍에서 '관용적(idiomatic)'은 무슨 뜻인가요?

특정 언어에 대해 프로그래밍 커뮤니티가 기대하는 규칙과 스타일을 따르는 코드를 쓴다는 뜻입니다. 그래서 코드가 더 자연스럽고 다른 사람이 이해하기 쉬워집니다.

수동 반복문 대신 `map`과 `select` 같은 메서드를 쓰는 이유는 무엇인가요?

이 메서드들은 대체로 더 짧고 읽기 쉬우며 오류가 적습니다. 효율적이기도 합니다.

'안티 패턴'이란 무엇인가요?

겉보기에는 작동하지만 실제로는 더 복잡하고 유지하기 어렵거나 비효율적인 코드를 만드는 흔한 코딩 방식입니다. 가이드는 이를 피하는 방법을 보여 줍니다.

상세 정보

작성자의 원본 설명

Language-specific super-code guidelines for ruby.

repo: sickn33/agentic-awesome-skills

인기도

GitHub 스타
48k
순위
#5897
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬