Comprehensive Ruby implementations of Gang of Four (GoF) design patterns. Use when implementing object-oriented design solutions, refactoring to reduce coupling, solving architecture problems, or when user mentions specific patterns (Factory, Singleton, Observer, Strategy, etc.) in Ruby context.
Provides Ruby implementations of all 23 Gang of Four design patterns. Use when user mentions specific patterns (Factory, Singleton, Observer, Strategy, etc.) in Ruby context, or when solving object-oriented design problems like decoupling creation, managing dependencies, or handling state transitions.
/plugin marketplace add el-feo/ai-context/plugin install ruby-rails@jebs-dev-toolsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/behavioral-patterns.mdreferences/creational-patterns.mdreferences/structural-patterns.md<quick_start> <pattern_selection> Object Creation Problems → Creational Patterns
Structural Problems → Structural Patterns
Behavioral Problems → Behavioral Patterns
<ruby_abstract_method> Ruby doesn't have built-in abstract methods. Use:
def abstract_method
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
end
</ruby_abstract_method> </quick_start>
<when_to_use> Use this skill when encountering:
<pattern_quick_reference> <creational> Factory Method - Define interface for creation, let subclasses decide type
class Creator
def factory_method
raise NotImplementedError
end
def operation
product = factory_method
"Working with #{product.operation}"
end
end
class ConcreteCreator < Creator
def factory_method
ConcreteProduct.new
end
end
File: Ruby/src/factory_method/conceptual/main.rb
Singleton (thread-safe)
class Singleton
@instance_mutex = Mutex.new
private_class_method :new
def self.instance
return @instance if @instance
@instance_mutex.synchronize { @instance ||= new }
@instance
end
end
File: Ruby/src/singleton/conceptual/thread_safe/main.rb
See references/creational-patterns.md for Abstract Factory, Builder, Prototype. </creational>
<structural> **Decorator** - Wrap objects to add behavior dynamically ```ruby class Decorator < Component def initialize(component) @component = component enddef operation @component.operation end end
class ConcreteDecorator < Decorator def operation "Decorated(#{@component.operation})" end end
decorated = DecoratorB.new(DecoratorA.new(ConcreteComponent.new))
File: `Ruby/src/decorator/conceptual/main.rb`
**Adapter** - Convert interface to expected format
```ruby
class Adapter < Target
def initialize(adaptee)
@adaptee = adaptee
end
def request
"Adapted: #{@adaptee.specific_request}"
end
end
File: Ruby/src/adapter/conceptual/main.rb
See references/structural-patterns.md for Bridge, Composite, Facade, Flyweight, Proxy. </structural>
<behavioral> **Strategy** - Swap algorithms at runtime ```ruby class Context attr_writer :strategydef initialize(strategy) @strategy = strategy end
def execute @strategy.do_algorithm(data) end end
context = Context.new(StrategyA.new) context.strategy = StrategyB.new
File: `Ruby/src/strategy/conceptual/main.rb`
**Observer** - Notify subscribers of state changes
```ruby
class Subject
def initialize
@observers = []
end
def attach(observer)
@observers << observer
end
def detach(observer)
@observers.delete(observer)
end
def notify
@observers.each { |observer| observer.update(self) }
end
end
File: Ruby/src/observer/conceptual/main.rb
State - Object behavior changes based on internal state
class Context
attr_accessor :state
def transition_to(state)
@state = state
@state.context = self
end
def request
@state.handle
end
end
File: Ruby/src/state/conceptual/main.rb
See references/behavioral-patterns.md for Chain of Responsibility, Command, Iterator, Mediator, Memento, Template Method, Visitor. </behavioral> </pattern_quick_reference>
<ruby_idioms> <deep_copy> For Prototype pattern, use Marshal for deep copying:
Marshal.load(Marshal.dump(object))
</deep_copy>
<thread_safety> For Singleton and shared resources, use Mutex:
@mutex = Mutex.new
@mutex.synchronize { @instance ||= new }
</thread_safety>
<private_constructor> For Singleton pattern:
private_class_method :new
</private_constructor>
<accessors> - `attr_reader :name` - read-only - `attr_writer :name` - write-only - `attr_accessor :name` - read/write </accessors><type_docs> Use YARD-style documentation:
# @param [String] value
# @return [Boolean]
def method(value)
end
</type_docs> </ruby_idioms>
<running_examples>
ruby Ruby/src/<pattern>/conceptual/main.rb
# Examples:
ruby Ruby/src/singleton/conceptual/thread_safe/main.rb
ruby Ruby/src/observer/conceptual/main.rb
ruby Ruby/src/strategy/conceptual/main.rb
ruby Ruby/src/decorator/conceptual/main.rb
Requires Ruby 3.2+. </running_examples>
<detailed_references>
<success_criteria>
ruby Ruby/src/<pattern>/conceptual/main.rb
</success_criteria>This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.