用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/miles990/claude-software-skills --skill ruby命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | ruby |
| description | Ruby programming patterns and idioms |
| domain | programming-languages |
| version | 1.0.0 |
| tags | ["ruby","rails","metaprogramming","blocks","gems"] |
| triggers | {"keywords":{"primary":["ruby","rails","ruby on rails","gem","bundler","rake"],"secondary":["metaprogramming","block","yield","rspec","sidekiq","activerecord"]},"context_boost":["web","backend","scripting","startup","rapid-development"],"context_penalty":["python","javascript","java","go"],"priority":"medium"} |
Ruby programming patterns including blocks, metaprogramming, and idiomatic Ruby code.
# Class definition
class User
attr_accessor :name, :email
attr_reader :id
attr_writer :password
# Class variable
@@count = 0
# Class method
def self.count
@@count
end
# Initialize
def initialize(name, email)
@id = SecureRandom.uuid
@name = name
@email = email
@@count += 1
end
# Instance method
def display_name
"#{name} <#{email}>"
end
# Private methods
private
def validate_email
email.include?('@')
end
end
# Inheritance
class Admin < User
attr_accessor :permissions
def initialize(name, email, permissions = [])
super(name, email)
@permissions = permissions
end
def has_permission?(perm)
permissions.include?(perm)
end
end
# Modules for mixins
module Timestampable
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def timestamped_attrs
[:created_at, :updated_at]
end
end
def touch
@updated_at = Time.now
end
def created_at
@created_at ||= Time.now
end
end
# Including module
class Document
include Timestampable
include Comparable
attr_accessor :title, :content
def <=>(other)
title <=> other.title
end
end
# Module for namespacing
module MyApp
module Services
class UserService
def create(params)
# ...
end
end
end
end
# Block usage
[1, 2, 3].each { |n| puts n }
[1, 2, 3].map do |n|
n * 2
end
# Yield to block
def with_timing
start = Time.now
result = yield
elapsed = Time.now - start
puts "Elapsed: #{elapsed}s"
result
end
with_timing { sleep(0.1) }
# Block with arguments
def transform_items(items)
items.map { |item| yield(item) }
end
transform_items([1, 2, 3]) { |n| n * 2 }
# Check if block given
def optional_block
if block_given?
yield
else
"No block provided"
end
end
# Convert block to proc
def with_block(&block)
block.call(42)
end
# Proc
my_proc = Proc.new { |x| x * 2 }
my_proc.call()
my_lambda = ->(x) { x * }
my_lambda.call()
proc_example = .new { || x }
proc_example.call()
lambda_example = ->(x, y) { x }
[, , ].map(&)
# Array operations
numbers = [1, 2, 3, 4, 5]
# Map/collect
doubled = numbers.map { |n| n * 2 }
# Select/filter
evens = numbers.select(&:even?)
# Reject
odds = numbers.reject(&:even?)
# Reduce/inject
sum = numbers.reduce(0) { |acc, n| acc + n }
sum = numbers.reduce(:+)
# Each with index
numbers.each_with_index do |n, i|
puts "#{i}: #{n}"
end
# Find
found = numbers.find { |n| n > 3 }
# Any/all/none
numbers.any?(&:even?) # true
numbers.all? { |n| n > 0 } # true
numbers.none? { |n| n > 10 } # true
# Group by
users = [
{ name: 'Alice', role: 'admin' },
{ name: 'Bob', role: 'user' },
{ name: 'Charlie', role: 'admin' }
]
grouped = users.group_by { |u| u[:role] }
# => { 'admin' => [...], 'user' => [...] }
passed, failed = scores.partition { || s >= }
nested = [[, ], [, ]]
flat = nested.flat_map { || arr.map { || n * } }
(..).lazy
.select(&)
.map { || n * }
.take()
.to_a
()
= start
.downto() { || n }
.new().to_a
# Method missing
class DynamicProxy
def initialize(target)
@target = target
end
def method_missing(method, *args, &block)
puts "Calling #{method} with #{args}"
@target.send(method, *args, &block)
end
def respond_to_missing?(method, include_private = false)
@target.respond_to?(method) || super
end
end
# Define method dynamically
class User
ROLES = %w[admin moderator user]
ROLES.each do |role|
define_method("#{role}?") do
@role == role
end
end
end
# Class macro
class MyModel
def self.attribute(name, type)
define_method(name) do
instance_variable_get("@#{name}")
end
define_method() ||
instance_variable_set(, value)
attribute ,
attribute ,
.inherited(subclass)
puts
.method_added(method_name)
puts
.configure(&block)
instance_eval(&block)
.setting(name, value)
define_singleton_method(name) { value }
.configure
setting ,
setting ,
obj.send()
obj.public_send()
refine
downcase.gsub(, )
using
()
title.to_slug
# Basic exception handling
begin
risky_operation
rescue StandardError => e
puts "Error: #{e.message}"
puts e.backtrace.first(5).join("\n")
ensure
cleanup
end
# Multiple rescue clauses
begin
parse_file(path)
rescue Errno::ENOENT
puts "File not found"
rescue JSON::ParserError => e
puts "Invalid JSON: #{e.message}"
rescue => e
puts "Unknown error: #{e.class}"
end
# Retry
attempts = 0
begin
attempts += 1
connect_to_server
rescue ConnectionError
retry if attempts < 3
raise
end
# Custom exceptions
class AppError < StandardError
attr_reader :code
def initialize(message, code: nil)
super(message)
@code = code
<
()
()
= errors
.new({ [] })
process_order(order)
=> e
,
.success(value)
new( value)
.failure(error)
new( error)
()
= value
= error
error.?
!success?
failure?
(value)
()
.failure() params[]
user = .create(params)
.success(user)
=> e
.failure(e.message)
# spec/models/user_spec.rb
require 'rails_helper'
RSpec.describe User, type: :model do
describe 'validations' do
it { is_expected.to validate_presence_of(:email) }
it { is_expected.to validate_uniqueness_of(:email) }
end
describe 'associations' do
it { is_expected.to have_many(:posts) }
it { is_expected.to belong_to(:organization) }
end
describe '#display_name' do
subject(:user) { build(:user, name: 'John', email: 'john@example.com') }
it 'returns formatted name with email' do
expect(user.display_name).to eq('John <john@example.com>')
end
end
describe '.active' do
let!(:active_user) { create(:user, active: true) }
let!(:inactive_user) { create(:user, active: false) }
it 'returns only active users' do
expect(User.active).to contain_exactly(active_user)
end
end
context 'when user is admin' do
subject() { build(, ) }
it
expect(admin).to be_admin
.describe
describe
subject() { described_class.new }
let() { { , } }
let() { instance_double() }
before
allow().to receive().and_return(email_service)
allow(email_service).to receive()
it
expect { service.create(params) }.to change(, ).by()
it
service.create(params)
expect(email_service).to have_received()
context
let() { { } }
it
expect { service.create(params) }.to raise_error()
# Threads
threads = []
results = []
mutex = Mutex.new
5.times do |i|
threads << Thread.new do
result = heavy_computation(i)
mutex.synchronize { results << result }
end
end
threads.each(&:join)
# Thread pool with Concurrent Ruby
require 'concurrent'
pool = Concurrent::FixedThreadPool.new(5)
futures = urls.map do |url|
Concurrent::Future.execute(executor: pool) do
fetch_url(url)
end
end
results = futures.map(&:value)
# Async/await with Async gem
require 'async'
Async do
results = urls.map do |url|
Async do
fetch_url(url)
end
end.map(&:wait)
end
# Fiber (cooperative concurrency)
fiber = Fiber.new do
puts "Start"
Fiber.yield 1
puts "Middle"
Fiber.yield 2
puts "End"
fiber.resume
fiber.resume
fiber.resume
ractor = .new
val = .receive
val *
ractor.send()
result = ractor.take