skillfed

ruby

This skill teaches core Ruby patterns including classes, modules, inheritance, and mixins alongside functional programming with blocks, procs, and lambdas. It covers enumerable operations, lazy evaluation, and metaprogramming techniques like method_missing and dynamic method definition, plus error handling strategies and RSpec testing.

Ruby teaches programming patterns, blocks, metaprogramming, and idiomatic code for web development.

AI-generated summary based on this skill's SKILL.md

19 5 MIT updated by miles990

Install

miles990/claude-software-skills/ruby · repository language: TypeScript

git clone https://github.com/miles990/claude-software-skills
cp -r claude-software-skills/programming-languages/ruby ~/.claude/skills/ruby
npx skillfed install miles990/claude-software-skills/ruby

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

How do blocks and yield work in Ruby?

Ruby blocks are anonymous code chunks passed to methods. The yield keyword executes the block within a method's context. Ruby uses blocks extensively—iterators like `each` and `map` accept blocks. Blocks can access the method's local variables and return values to the caller. Understanding blocks is fundamental to Ruby's functional programming style and idiomatic code patterns.

What are Ruby's metaprogramming techniques like method_missing?

Ruby metaprogramming lets you write code that writes code. method_missing intercepts calls to undefined methods, enabling dynamic method handling. define_method creates methods at runtime. Ruby also supports refinements for scoped monkey patching and symbol-to-proc conversion for compact functional syntax. These techniques power Rails' elegant DSLs and ActiveRecord's dynamic finders.

What's the difference between Ruby lambdas vs procs?

Ruby lambdas and procs are both callable objects, but differ in strictness and return behavior. Lambdas enforce argument count and return to their enclosing method; procs are lenient with arguments and return from the enclosing method. Lambdas are stricter and safer for most use cases. Both support closures and can be passed as block arguments using the & operator.

How do Ruby classes, modules, and inheritance work together?

Ruby classes inherit from a single parent (default: Object). Modules provide mixins—reusable behavior included into classes. Multiple modules can be mixed into one class, enabling composition. Inheritance chains methods vertically; modules add methods horizontally. Ruby's method lookup follows the inheritance chain, then included modules in reverse order. This design avoids multiple inheritance complexity while supporting flexible code reuse.

What testing approach does Ruby use with RSpec?

RSpec is Ruby's dominant testing framework using a behavior-driven development (BDD) syntax. Tests read like specifications: `describe`, `context`, and `it` blocks structure tests. Matchers like `expect(value).to eq(expected)` assert outcomes. RSpec supports mocking, stubbing, and fixtures. Combined with proper error handling and exception testing, RSpec enables comprehensive test coverage for Ruby applications.

How do Rails gems and Bundler manage Ruby dependencies?

Ruby on Rails relies on gems—packaged libraries—for functionality. Bundler manages gem dependencies via a Gemfile, resolving version conflicts and locking versions in Gemfile.lock. Rails itself is a gem providing MVC structure, ActiveRecord ORM, and routing. Bundler ensures consistent environments across development, testing, and production. Understanding gem management is essential for Rails backend development and following Ruby on Rails best practices.

SKILL.md

rendered from the published skill — quoted content, verbatim

Ruby

Overview

Ruby programming patterns including blocks, metaprogramming, and idiomatic Ruby code.


Core Ruby Patterns

Classes and Modules

```ruby

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

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 4 files
programming-languages/ruby/SKILL.md
programming-languages/ruby/templates/.rubocop.yml
programming-languages/ruby/templates/Gemfile
programming-languages/ruby/templates/README.md

Related skills

Tags

dynamic-code-generation functional-programming object-oriented-design concurrent-execution collection-operations web-framework testing-framework exception-patterns code-introspection async-programming