coding-ruby
Ruby 3.x: blocks/procs/lambdas, metaprogramming, modules, bundler, gems, Rails, RSpec
What this skill does
# coding-ruby
## Purpose
This skill allows the AI to generate, debug, and optimize Ruby 3.x code, focusing on advanced constructs like blocks, procs, lambdas, metaprogramming, modules, gem management with Bundler, Rails web apps, and RSpec testing.
## When to Use
Use this skill for tasks involving Ruby scripting, such as building web applications with Rails, managing dependencies via Bundler, writing unit tests with RSpec, or applying metaprogramming for dynamic code generation. Apply it when users request code for e-commerce sites, API backends, or custom gems.
## Key Capabilities
- Handle blocks and procs: Define and yield blocks in methods, e.g., for iterators.
- Implement metaprogramming: Use `define_method` or `method_missing` for dynamic class creation.
- Manage modules: Create and include modules for namespacing, like `module MyModule; end`.
- Work with Bundler: Install and manage gems via Gemfiles for dependency resolution.
- Build Rails apps: Generate models, controllers, and routes for MVC architecture.
- Write RSpec tests: Create specs for behavior-driven development, including matchers and mocks.
## Usage Patterns
To accomplish tasks, structure code with Ruby's idioms: use procs for callbacks, modules for reusable code, and metaprogramming for automation. For Rails, follow the MVC pattern; for RSpec, use describe/it blocks. Always check Ruby 3.x syntax, like pattern matching with `case` statements. To define a lambda: `my_lambda = ->(x) { x * 2 }`. Invoke it as `my_lambda.call(5)`. For metaprogramming, add methods dynamically: `class MyClass; define_method(:greet) { puts 'Hello' }; end`. Integrate Bundler by running `bundle install` after editing Gemfiles.
## Common Commands/API
Use these exact commands for Ruby tasks:
- Ruby CLI: Run `ruby -v` to verify version (e.g., 3.2.2), or start IRB with `irb` for interactive testing.
- Bundler: Execute `bundle install --path vendor/bundle` to install gems from a Gemfile; update with `bundle update gem_name`.
- Gems: Add a gem via Gemfile: `gem 'rspec', '~> 3.12'`; then run `bundle install`.
- Rails: Generate a new app with `rails new my_app --database=postgresql`; create a controller: `rails generate controller Users index`.
- RSpec: Run tests with `rspec spec/`, or a specific file: `rspec spec/models/user_spec.rb --format documentation`.
- API endpoints in Rails: Define routes in `config/routes.rb`, e.g., `resources :users`; access via `/users` in code.
Config formats: Use YAML for Rails configs, e.g., in `config/database.yml`: `default: &default adapter: postgresql username: user`. For authentication in gems, set env vars like `$RAILS_MASTER_KEY` for encrypted credentials.
## Integration Notes
Integrate this skill by setting up a Ruby environment first: Install Ruby 3.x via rbenv with `rbenv install 3.2.2` and set it globally with `rbenv global 3.2.2`. For Rails, add to Gemfile and run `bundle exec rails server` to start on port 3000. Use Bundler for gem isolation: Create a new gem set with `bundle init` and require gems in code like `require 'rspec'`. If external APIs are involved (e.g., via gems), handle auth with env vars: Set `$GEM_API_KEY` and access it in code as `ENV['GEM_API_KEY']`. For database integration, configure ActiveRecord in Rails models, e.g., `class User < ApplicationRecord; end`, and migrate with `rails db:migrate`.
## Error Handling
Handle Ruby errors prescriptively: Use begin/rescue blocks for exceptions, e.g.:
```ruby
begin
File.open('nonexistent.txt')
rescue Errno::ENOENT => e
puts "File not found: #{e.message}"
end
```
For Rails, check logs in `log/development.log` and use `rescue_from` in controllers for custom errors. In RSpec, expect errors with `expect { code }.to raise_error(SomeError)`. Common issues: Gem conflicts—resolve with `bundle clean --force`; syntax errors in Ruby 3.x—use `ruby -c file.rb` to check. For metaprogramming, catch NoMethodError with `method_missing` to define fallback behavior.
## Graph Relationships
- Related to: coding-python (shares metaprogramming concepts), coding-javascript (both use modules and callbacks).
- Clusters: Linked to "coding" cluster for general programming skills; connects to "web-development" via Rails integration.
- Dependencies: Requires "environment-setup" for Ruby installation; extends "testing-frameworks" through RSpec.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.